简体   繁体   English

Windows Phone DateTime异常

[英]Windows Phone DateTime exception

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(). 我目前正在本地化Windows Phone应用程序,但已经开始在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] 

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. 我的应用程序已本地化,并且未使用正确格式的区域性代码,例如,我将使用en代替en-US或使用fr代替fr-FR。

Once I became specific as explained above, the DateTime.Now.ToString() began to work as expected. 如上所述,一旦我变得很具体, DateTime.Now.ToString()开始按预期工作。

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. 根据MSDN文档ToString()方法返回当前区域性所使用的日历中日期和时间的字符串表示形式。 If the value of the current DateTime instance is earlier than Calendar.MinSupportedDateTime or later than Calendar.MaxSupportedDateTime, the method throws an ArgumentOutOfRangeException . 如果当前DateTime实例的值早于Calendar.MinSupportedDateTime或晚于Calendar.MaxSupportedDateTime,则该方法将引发ArgumentOutOfRangeException

What is the current culture in your app? 您的应用当前的文化是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM