Reputation: 65
I'm currently working on localizing a Windows Phone application but I've started getting an index out of range exception on DateTime.Now.ToString().
I've tried changing the timezone of my computer but the error persists.
I'm unsure of what caused this problem or what to do to fix it.
Any ideas? Thanks in advance!
STACK TRACE (added on request)
mscorlib.dll!System.Globalization.DateTimeFormatInfo.GetYearMonthPattern(int calID = 1) + 0x25 bytes
mscorlib.dll!System.Globalization.DateTimeFormatInfo.InitializeOverridableProperties() + 0x94 bytes
mscorlib.dll!System.Globalization.DateTimeFormatInfo.Calendar.set(System.Globalization.Calendar value = {System.Globalization.GregorianCalendar}) + 0x1a8 bytes
mscorlib.dll!System.Globalization.DateTimeFormatInfo.DateTimeFormatInfo(System.Globalization.CultureTableRecord cultureTable = {System.Globalization.CultureTableRecord}, System.Globalization.Calendar cal = {System.Globalization.GregorianCalendar}) + 0x29 bytes
mscorlib.dll!System.Globalization.CultureInfo.DateTimeFormat.get() + 0x19 bytes
mscorlib.dll!System.Globalization.CultureInfo.GetFormat(System.Type formatType = {Name = "DateTimeFormatInfo" FullName = "System.Globalization.DateTimeFormatInfo"}) + 0x22 bytes
mscorlib.dll!System.Globalization.DateTimeFormatInfo.CurrentInfo.get() + 0x2a bytes
mscorlib.dll!System.DateTime.ToString()
> QuickAirtime.dll!QuickAirtime.PaymentSummary.btnTransactionClick(object sender = {System.Windows.Controls.Button}, System.Windows.RoutedEventArgs e = {System.Windows.RoutedEventArgs}) Line 78 + 0x2 bytes C#
System.Windows.dll!System.Windows.Controls.Primitives.ButtonBase.OnClick() + 0x1f bytes
System.Windows.dll!System.Windows.Controls.Button.OnClick() + 0x1f bytes
System.Windows.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}) + 0x4e bytes
System.Windows.dll!System.Windows.Controls.Control.OnMouseLeftButtonUp(System.Windows.Controls.Control ctrl = {System.Windows.Controls.Button}, System.EventArgs e = {System.Windows.Input.MouseButtonEventArgs}) + 0xc bytes
System.Windows.dll!MS.Internal.JoltHelper.FireEvent(System.IntPtr unmanagedObj = 227599168, System.IntPtr unmanagedObjArgs = 227256368, int argsTypeIndex = 169, int actualArgsTypeIndex = 169, string eventName = "M@@4") + 0x115 bytes
[External Code]
Upvotes: 0
Views: 522
Reputation: 65
My app was localized and I did not use Culture Codes in the correct format, for example, I would use en instead of en-US or fr instead of fr-FR.
Once I became specific as explained above, the DateTime.Now.ToString()
began to work as expected.
Upvotes: 1
Reputation: 171804
This can happen if the date is invalid for the current culture's calendar.
According to the MSDN documentation: The ToString() method returns the string representation of the date and time in the calendar used by the current culture. If the value of the current DateTime instance is earlier than Calendar.MinSupportedDateTime or later than Calendar.MaxSupportedDateTime, the method throws an ArgumentOutOfRangeException.
What is the current culture in your app?
Upvotes: 0