Created attachment 24441 [details]
Previously I reported bug with Thai culture (https://bugzilla.xamarin.com/show_bug.cgi?id=31228).
It was indeed fixed and now works fine, but now I experience another bug which can be reproduced using the attached project. All encodings are checked and included in the project.
In order to reproduce it set android phone language (I tested it on android 4.4) to be Thai language.
Put the following line in the OnCreate:
var date = DateTime.Parse("2000-31-07");
var date = DateTime.ParseExact("2000-31-07","yyyy-dd-MM",null);
And it will crash at runtime with the following exception:
System.ArgumentOutOfRangeException: Not a valid calendar for the given culture.
Parameter name: value
at System.Globalization.DateTimeFormatInfo.set_Calendar (System.Globalization.Calendar value) [0x00154] in <9e5b8ac258034478aed80c25b6e73e52>:0
at System.Globalization.DateTimeFormatInfo..ctor (System.Globalization.CultureData cultureData, System.Globalization.Calendar cal) [0x00022] in <9e5b8ac258034478aed80c25b6e73e52>:0
at System.Globalization.CultureInfo.get_DateTimeFormat () [0x00033] in <9e5b8ac258034478aed80c25b6e73e52>:0
at System.Globalization.CultureInfo.GetFormat (System.Type formatType) [0x0002f] in <9e5b8ac258034478aed80c25b6e73e52>:0
at System.Globalization.DateTimeFormatInfo.get_CurrentInfo () [0x00021] in <9e5b8ac258034478aed80c25b6e73e52>:0
at System.DateTime.Parse (System.String s) [0x00000] in <9e5b8ac258034478aed80c25b6e73e52>:0
at ThaiBug2.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00009] in C:\Users\username\Documents\Visual Studio 2017\Projects\ThaiBug2\ThaiBug2\MainActivity.cs:14
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <947c88b5da6c4d94ab126d7acb391dc6>:0
at (wrapper dynamic-method) System.Object:bc4a6bc1-1943-4d65-9d85-57b6d5875e98 (intptr,intptr,intptr)
Seems like the problem is different. When I use no linking it does work, I mean second command (var date = DateTime.ParseExact("2000-31-07","yyyy-dd-MM",null);) I use Link option SDK Libraries, I don't want to ignore encoding libs. Because it's dumb to include them in order to ignore them by linker. I don't think I need to do the job twice in order to make this work. How do I skip them, I tried to skip the following, but it didn't affect crash:
mscorlib link skip doesn't work either.
Put the following somewhere in your code:
private void Init()
var t = typeof(System.Globalization.ThaiBuddhistCalendar);
Since I don't link my libs I don't even need to call it.
But the bug still remains. It shouldn't work this way.
Seems like Thai calendar is not prepared for linking properly.
Thank you for the report!
For those unfamiliar with Thai, it is the following option:
Settings -> Language -> ไทย
I was able to CONFIRM this issue and see that the linker is stripping away items in System.Globalization. I believe this is intended behavior unless there is static analysis showing the specific ThaiBuddhistCalendar being used in code(Which is how you worked around it). I would guess this would also happen for Korean, Chinese, Japanese, and other types of calendars in the System.Globalization class.
Seems like a mscorlib issue at this point.
Turns out my workaround didn't work in Release mode. I had to call the following method in the app ctor:
private static void InitThaiCalendarCrashFix()
var localeIdentifier = Java.Util.Locale.Default.ToString();
if (localeIdentifier == "th_TH")
Have you tried to pass the CultureInfo in as IFormatProvider to your Parse calls mentioned in the bug description?
var date = DateTime.Parse("2000-31-07", CultureInfo.InvariantCulture);
var date = DateTime.ParseExact("2000-31-07", "yyyy-dd-MM", CultureInfo.InvariantCulture);
I observe very similar crash with this code: "dateTimeObj.ToString("o");". https://github.com/onovotny/MetroLog/issues/110
@Jungmok I didn't try other approaches since my workaround solved the problem.