2012-06-28 62 views
0

我目前正在本地化Windows Phone應用程序,但我已經開始在DateTime.Now.ToString()上獲取一個超出範圍的異常索引。Windows Phone DateTime異常

我試過改變我的電腦的時區,但錯誤仍然存​​在。

我不確定是什麼導致了這個問題,或者怎麼解決它。

任何想法?提前致謝!


堆棧跟蹤(應要求加)


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 = "[email protected]@4") + 0x115 bytes  
    [External Code] 
+5

你確定這個異常是由DateTime.Now.ToString()引發的嗎?這似乎不可能。 (請發佈異常堆棧跟蹤) –

+0

@PhilippeLeybaert我已經編輯了問題以顯示StackTrace – user1477707

+0

你能告訴我們導致異常的實際代碼行(以及它周圍的幾行代碼),所以我們有一個最小的例子重現錯誤?另外:你是否強迫一種仿真器/電話設備不支持的文化? –

回答

0

如果日期是當前區域性的日曆無效就會發生這種情況。

根據MSDN documentationToString()方法返回當前區域使用的日曆中日期和時間的字符串表示形式。如果當前DateTime實例的值早於Calendar.MinSupportedDateTime或晚於Calendar.MaxSupportedDateTime,則該方法將拋出ArgumentOutOfRangeException

你的應用中的當前文化是什麼?

+0

我使用默認的en文化,我沒有指定US或GB。但不確定是否默認切換到倫敦或美國時間。在本地化的情況下,我如何確保應用文化選擇不會與電話文化發生衝突?即如果這是目前正在發生的事情。 – user1477707

+0

所以我很困惑,但是什麼提供日期到我的錯誤的情況?是否可以通過電話模擬器或電話模擬器將應用程序或應用程序添加到系統中?錯誤發生在哪裏,什麼是抱怨? – user1477707

1

我的應用程序已本地化,我沒有以正確的格式使用文化代碼,例如,我會使用en代替en-US或fr代替fr-FR。

一旦我變得具體如上所述,DateTime.Now.ToString()開始按預期工作。

相關問題