M
Me
Hi all
I am getting a really bizzare error on when I convert a string into a
datetime:
The code is :
DateTime dt1 = Convert.ToDateTime("10 Sep 2005");
Console.WriteLine(dt1.Year);
I have installed .Net 2.0, on xp Pro SP2. When I do the following I get
an error saying:
What is this? How strange. Its pretty vital that I can convert strings
to dates - anyone know where to start with this? I tried it in vb and
it still threw the same error.
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.GetSeparatorToken(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 tmpWin1.Form1.Form1_Load(Object sender, EventArgs e) in D:\My
Stuff\Programming\Net 2.0\C#\tmp\tmpWin1\tmpWin1\tmpWin1\Form1.cs:line
20
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef
hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at tmpWin1.Program.Main() in D:\My Stuff\Programming\Net
2.0\C#\tmp\tmpWin1\tmpWin1\tmpWin1\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(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()
This happens
I am getting a really bizzare error on when I convert a string into a
datetime:
The code is :
DateTime dt1 = Convert.ToDateTime("10 Sep 2005");
Console.WriteLine(dt1.Year);
I have installed .Net 2.0, on xp Pro SP2. When I do the following I get
an error saying:
What is this? How strange. Its pretty vital that I can convert strings
to dates - anyone know where to start with this? I tried it in vb and
it still threw the same error.
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.GetSeparatorToken(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 tmpWin1.Form1.Form1_Load(Object sender, EventArgs e) in D:\My
Stuff\Programming\Net 2.0\C#\tmp\tmpWin1\tmpWin1\tmpWin1\Form1.cs:line
20
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef
hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at tmpWin1.Program.Main() in D:\My Stuff\Programming\Net
2.0\C#\tmp\tmpWin1\tmpWin1\tmpWin1\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(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()
This happens