.NET 2.0 DateTime conversion error??

T

Tim

Hi,

I am trying to do something simple. Convert a string date to datetime but it
is not working and is giving me a baffling error!

System.Convert.ToDateTime("Jan 30, 2006")
'System.Convert.ToDateTime("Jan 30, 2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

System.Convert.ToDateTime("01/01/2006")
'System.Convert.ToDateTime("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}
System.Convert.ToDateTime(fParams.dtStartDate.Value)

Huh? What array is it talking about? I have done this many times in .NET 1.1
and it works just fine. This is a project that I have converted from .NET
1.1. The conversion was successful and it compiles with no errors, so what
is going on?

Please help, completely baffled.

Tim
 
O

Otis Mukinfus

Hi,

I am trying to do something simple. Convert a string date to datetime but it
is not working and is giving me a baffling error!

System.Convert.ToDateTime("Jan 30, 2006")
'System.Convert.ToDateTime("Jan 30, 2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

System.Convert.ToDateTime("01/01/2006")
'System.Convert.ToDateTime("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}
System.Convert.ToDateTime(fParams.dtStartDate.Value)

Huh? What array is it talking about? I have done this many times in .NET 1.1
and it works just fine. This is a project that I have converted from .NET
1.1. The conversion was successful and it compiles with no errors, so what
is going on?

Please help, completely baffled.

Tim

Try this:

DateTime dt = DateTime.Parse("01/01/2006");
DateTime dte = DateTime.Parse("Jan 30, 2006");


Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
T

Tim

Hi Otis,

Thanks for the reply, however this also fails on my system.

DateTime.Parse("01/01/2006")
'DateTime.Parse("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

That damn array just won't go away! Any more ideas?

Tim
 
B

Bill Butler

Tim said:
Hi Otis,

Thanks for the reply, however this also fails on my system.

DateTime.Parse("01/01/2006")
'DateTime.Parse("01/01/2006")' threw an exception of type 'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the array."}

That damn array just won't go away! Any more ideas?

Possibly because THAT DAMN ARRAY is the real problem.
I suspect that the Date conversion is NOT the cause of your problem.
Put some displays in or step through in debug.
Find the real cause of your problem

Hope this helps
Bill
 
W

William Stacey [MVP]

DateTime dt = System.Convert.ToDateTime("01/01/2006");
Console.WriteLine(dt);
dt = DateTime.Parse("01/01/2006");

Works here. You got something else going on. Post your code.
--
William Stacey [MVP]

| Hi Otis,
|
| Thanks for the reply, however this also fails on my system.
|
| DateTime.Parse("01/01/2006")
| 'DateTime.Parse("01/01/2006")' threw an exception of type
| 'System.IndexOutOfRangeException'
| base {System.SystemException}: {"Index was outside the bounds of the
| array."}
|
| That damn array just won't go away! Any more ideas?
|
| Tim
|
| | > On Mon, 30 Jan 2006 19:13:30 -0500, "Tim" <[email protected]>
| > wrote:
| >
| >>Hi,
| >>
| >>I am trying to do something simple. Convert a string date to datetime
but
| >>it
| >>is not working and is giving me a baffling error!
| >>
| >>System.Convert.ToDateTime("Jan 30, 2006")
| >>'System.Convert.ToDateTime("Jan 30, 2006")' threw an exception of type
| >>'System.IndexOutOfRangeException'
| >>base {System.SystemException}: {"Index was outside the bounds of the
| >>array."}
| >>
| >>System.Convert.ToDateTime("01/01/2006")
| >>'System.Convert.ToDateTime("01/01/2006")' threw an exception of type
| >>'System.IndexOutOfRangeException'
| >>base {System.SystemException}: {"Index was outside the bounds of the
| >>array."}
| >>System.Convert.ToDateTime(fParams.dtStartDate.Value)
| >>
| >>Huh? What array is it talking about? I have done this many times in .NET
| >>1.1
| >>and it works just fine. This is a project that I have converted from
..NET
| >>1.1. The conversion was successful and it compiles with no errors, so
what
| >>is going on?
| >>
| >>Please help, completely baffled.
| >>
| >>Tim
| >>
| >>
| >>
| >
| > Try this:
| >
| > DateTime dt = DateTime.Parse("01/01/2006");
| > DateTime dte = DateTime.Parse("Jan 30, 2006");
| >
| >
| > Otis Mukinfus
| > http://www.otismukinfus.com
| > http://www.tomchilders.com
|
|
 
O

Otis Mukinfus

Hi Otis,

Thanks for the reply, however this also fails on my system.

DateTime.Parse("01/01/2006")
'DateTime.Parse("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

That damn array just won't go away! Any more ideas?

Tim
[snip]

Gosh, Tim! I think something else is wrong. Have you stepped through
the code with the debugger (I mean ALL the lines before the method
calls)? It ain't happening in the code I sent you.

Paste the code below into a NEW console application, replacing all of
the default code and see what happens:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
DateTime dt = DateTime.Parse("01/01/2006");
DateTime dte = DateTime.Parse("Jan 30, 2006");
}
}
}

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
T

Tim

Hi Otis,

I pasted the code you gave me into a console application, ran it and got the
exact same error. It would seem to make sense that it is not in the datetime
convert function, however what array is it talking about?

The error seems to originate from mscorlib.dll. Does that make any sense? I
have a clean install of XP pro with .NET 2.0 on it. I had this problem on my
other machine and I orginally thought it was because I had .NET 1.1 and .NET
2.0 on the same machine.

I have done this datetime conversion function many times with .NET 1.1, so
that is why I am so baffled.

Tim

Otis Mukinfus said:
Hi Otis,

Thanks for the reply, however this also fails on my system.

DateTime.Parse("01/01/2006")
'DateTime.Parse("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

That damn array just won't go away! Any more ideas?

Tim
[snip]

Gosh, Tim! I think something else is wrong. Have you stepped through
the code with the debugger (I mean ALL the lines before the method
calls)? It ain't happening in the code I sent you.

Paste the code below into a NEW console application, replacing all of
the default code and see what happens:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
DateTime dt = DateTime.Parse("01/01/2006");
DateTime dte = DateTime.Parse("Jan 30, 2006");
}
}
}

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
W

William Stacey [MVP]

Try/catch the exception and write it to the console an post here. This is
weird.

--
William Stacey [MVP]

| Hi Otis,
|
| I pasted the code you gave me into a console application, ran it and got
the
| exact same error. It would seem to make sense that it is not in the
datetime
| convert function, however what array is it talking about?
|
| The error seems to originate from mscorlib.dll. Does that make any sense?
I
| have a clean install of XP pro with .NET 2.0 on it. I had this problem on
my
| other machine and I orginally thought it was because I had .NET 1.1 and
..NET
| 2.0 on the same machine.
|
| I have done this datetime conversion function many times with .NET 1.1, so
| that is why I am so baffled.
|
| Tim
|
| | > On Mon, 30 Jan 2006 20:26:43 -0500, "Tim" <[email protected]>
| > wrote:
| >
| >>Hi Otis,
| >>
| >>Thanks for the reply, however this also fails on my system.
| >>
| >>DateTime.Parse("01/01/2006")
| >>'DateTime.Parse("01/01/2006")' threw an exception of type
| >>'System.IndexOutOfRangeException'
| >>base {System.SystemException}: {"Index was outside the bounds of the
| >>array."}
| >>
| >>That damn array just won't go away! Any more ideas?
| >>
| >>Tim
| > [snip]
| >
| > Gosh, Tim! I think something else is wrong. Have you stepped through
| > the code with the debugger (I mean ALL the lines before the method
| > calls)? It ain't happening in the code I sent you.
| >
| > Paste the code below into a NEW console application, replacing all of
| > the default code and see what happens:
| >
| > using System;
| > using System.Collections.Generic;
| > using System.Text;
| > using System.Data;
| >
| > namespace TestConsole
| > {
| > class Program
| > {
| > static void Main(string[] args)
| > {
| > DateTime dt = DateTime.Parse("01/01/2006");
| > DateTime dte = DateTime.Parse("Jan 30, 2006");
| > }
| > }
| > }
| >
| > Otis Mukinfus
| > http://www.otismukinfus.com
| > http://www.tomchilders.com
|
|
 
W

William Stacey [MVP]

Other thing. What language version of Windows and .Net 2.0?

--
William Stacey [MVP]

| Try/catch the exception and write it to the console an post here. This is
| weird.
|
| --
| William Stacey [MVP]
|
| || Hi Otis,
||
|| I pasted the code you gave me into a console application, ran it and got
| the
|| exact same error. It would seem to make sense that it is not in the
| datetime
|| convert function, however what array is it talking about?
||
|| The error seems to originate from mscorlib.dll. Does that make any sense?
| I
|| have a clean install of XP pro with .NET 2.0 on it. I had this problem on
| my
|| other machine and I orginally thought it was because I had .NET 1.1 and
| .NET
|| 2.0 on the same machine.
||
|| I have done this datetime conversion function many times with .NET 1.1,
so
|| that is why I am so baffled.
||
|| Tim
||
|| || > On Mon, 30 Jan 2006 20:26:43 -0500, "Tim" <[email protected]>
|| > wrote:
|| >
|| >>Hi Otis,
|| >>
|| >>Thanks for the reply, however this also fails on my system.
|| >>
|| >>DateTime.Parse("01/01/2006")
|| >>'DateTime.Parse("01/01/2006")' threw an exception of type
|| >>'System.IndexOutOfRangeException'
|| >>base {System.SystemException}: {"Index was outside the bounds of the
|| >>array."}
|| >>
|| >>That damn array just won't go away! Any more ideas?
|| >>
|| >>Tim
|| > [snip]
|| >
|| > Gosh, Tim! I think something else is wrong. Have you stepped through
|| > the code with the debugger (I mean ALL the lines before the method
|| > calls)? It ain't happening in the code I sent you.
|| >
|| > Paste the code below into a NEW console application, replacing all of
|| > the default code and see what happens:
|| >
|| > using System;
|| > using System.Collections.Generic;
|| > using System.Text;
|| > using System.Data;
|| >
|| > namespace TestConsole
|| > {
|| > class Program
|| > {
|| > static void Main(string[] args)
|| > {
|| > DateTime dt = DateTime.Parse("01/01/2006");
|| > DateTime dte = DateTime.Parse("Jan 30, 2006");
|| > }
|| > }
|| > }
|| >
|| > Otis Mukinfus
|| > http://www.otismukinfus.com
|| > http://www.tomchilders.com
||
||
|
|
 
O

Otis Mukinfus

Hi Otis,

I pasted the code you gave me into a console application, ran it and got the
exact same error. It would seem to make sense that it is not in the datetime
convert function, however what array is it talking about?

The error seems to originate from mscorlib.dll. Does that make any sense? I
have a clean install of XP pro with .NET 2.0 on it. I had this problem on my
other machine and I orginally thought it was because I had .NET 1.1 and .NET
2.0 on the same machine.

I have done this datetime conversion function many times with .NET 1.1, so
that is why I am so baffled.

Tim
[snip]

I'm stupefied Tim. I can't imagine what it could be.

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
T

Tim Cowan

Hi William,

I have reached the conclusion that something is corrupted somewhere. I even
tried
DateTime dt = System.Convert.ToDateTime("fishcakes");
and got the same error as below, it didn't even try to convert it.

Using C# on XP Pro SP2, US English, P4 2.6

Tim


System.IndexOutOfRangeException was unhandled
Message="Index was outside the bounds of the array."
Source="mscorlib"
StackTrace:
at System.Globalization.DateTimeFormatInfo.InsertHash(TokenHashValue[]
hashTable, String str, TokenType tokenType, Int32 tokenValue)
at System.Globalization.DateTimeFormatInfo.CreateTokenHashTable()
at System.Globalization.DateTimeFormatInfo.Tokenize(TokenType
TokenMask, TokenType& tokenType, Int32& tokenValue, __DTString& str)
at System.__DTString.GetRegularToken(TokenType& tokenType,
Int32& tokenValue, DateTimeFormatInfo dtfi)
at System.DateTimeParse.Lex(DS dps, __DTString& str,
DateTimeToken& dtok, DateTimeRawInfo& raw, DateTimeResult& result,
DateTimeFormatInfo& dtfi)
at System.DateTimeParse.TryParse(String s, DateTimeFormatInfo
dtfi, DateTimeStyles styles, DateTimeResult& result)
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo
dtfi, DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider)
at System.Convert.ToDateTime(String value)
at ConsoleApplication1.Program.Main(String[] args) in
C:\Documents and Settings\Tim\My Documents\Visual Studio
2005\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line
12
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


William Stacey said:
Try/catch the exception and write it to the console an post here. This is
weird.

--
William Stacey [MVP]

| Hi Otis,
|
| I pasted the code you gave me into a console application, ran it and got
the
| exact same error. It would seem to make sense that it is not in the
datetime
| convert function, however what array is it talking about?
|
| The error seems to originate from mscorlib.dll. Does that make any
sense?
I
| have a clean install of XP pro with .NET 2.0 on it. I had this problem
on
my
| other machine and I orginally thought it was because I had .NET 1.1 and
.NET
| 2.0 on the same machine.
|
| I have done this datetime conversion function many times with .NET 1.1,
so
| that is why I am so baffled.
|
| Tim
|
| | > On Mon, 30 Jan 2006 20:26:43 -0500, "Tim" <[email protected]>
| > wrote:
| >
| >>Hi Otis,
| >>
| >>Thanks for the reply, however this also fails on my system.
| >>
| >>DateTime.Parse("01/01/2006")
| >>'DateTime.Parse("01/01/2006")' threw an exception of type
| >>'System.IndexOutOfRangeException'
| >>base {System.SystemException}: {"Index was outside the bounds of the
| >>array."}
| >>
| >>That damn array just won't go away! Any more ideas?
| >>
| >>Tim
| > [snip]
| >
| > Gosh, Tim! I think something else is wrong. Have you stepped through
| > the code with the debugger (I mean ALL the lines before the method
| > calls)? It ain't happening in the code I sent you.
| >
| > Paste the code below into a NEW console application, replacing all of
| > the default code and see what happens:
| >
| > using System;
| > using System.Collections.Generic;
| > using System.Text;
| > using System.Data;
| >
| > namespace TestConsole
| > {
| > class Program
| > {
| > static void Main(string[] args)
| > {
| > DateTime dt = DateTime.Parse("01/01/2006");
| > DateTime dte = DateTime.Parse("Jan 30, 2006");
| > }
| > }
| > }
| >
| > Otis Mukinfus
| > http://www.otismukinfus.com
| > http://www.tomchilders.com
|
|
 
S

Stephen Lewis

Tim

Did you ever resolve your date conversion (Index outside bounds of
array) error when using CDate?

I am having the same problem, it is a very strange error when doing
something so simple.

Look forward to hearing how you fixed this.

Stephen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top