Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash "Not a valid calendar for the given culture" with Thai locale #2511

Closed
velocitysystems opened this issue Dec 10, 2018 · 9 comments
Closed
Labels
Area: Linker Issues when linking assemblies.

Comments

@velocitysystems
Copy link

velocitysystems commented Dec 10, 2018

Steps to Reproduce

  1. Set the device language to Thai.
  2. Use the following code snippet:
var timeSpan = TimeSpan.FromMinutes(65);
timeSpan.ToString(@"h\:mm\:ss")
  1. Runtime crash with System.ArgumentOutOfRangeException.

Expected Behavior

The method should complete successfully.

Actual Behavior

Throws System.ArgumentOutOfRangeException: Not a valid calendar for the given culture.

Workaround

Prevent linker from stripping out the reference by including it in the code.

_ = new System.Globalization.ThaiBuddhistCalendar();

Version Information

  • Microsoft Visual Studio Professional 2017 v15.9.3
    VisualStudio.15.Release/15.9.3+28307.145
    Microsoft .NET Framework
    Version 4.7.03062

  • Xamarin 4.12.3.73 (d15-9@20b35b881)
    Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

  • Xamarin Designer 4.16.5 (6b9f32067)
    Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

  • Xamarin Templates 1.1.127 (e975299)
    Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

  • Xamarin.Android SDK 9.1.0.38 (HEAD/61d16aa23)
    Xamarin.Android Reference Assemblies and MSBuild support.

  • Xamarin.iOS and Xamarin.Mac SDK 12.2.1.11 (5ef73d3)
    Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Related

Previously reported:

@shnaz
Copy link

shnaz commented Jul 25, 2019

Have same problem with arabic. Fixed it by using your workaround @velocitysystems. Thanks!

@AhmedKhattab95
Copy link

@shnaz what was the workaround ?

@shnaz
Copy link

shnaz commented Feb 24, 2020

@AhmedKhattab95 Just call this method early in your MainActivity.OnCreate:

		private void PreventLinkerFromStrippingCommonLocalizationReferences()
		{
			var gregorianCalendar = new System.Globalization.GregorianCalendar();
			var persianCalendar = new System.Globalization.PersianCalendar();
			var arabivAlQuraCalendar = new System.Globalization.UmAlQuraCalendar();
		}

@Mogikan
Copy link

Mogikan commented Aug 23, 2020

5 years since I reported this bug to bugzilla. Now got the hit from Arabic calendar. You should add code to the Application. Since Application is single, while there are many activities. And it's better to make PreventLinkerFromStrippingCommonLocalizationReferences static. Have not tried it, but it may be even not necessary to call the code in order to make linker work properly. https://guides.codepath.com/android/Understanding-the-Android-Application-Class

@BurkusCat
Copy link

In case it helps anyone in the future here is a larger method with all calendars based on the existing workarounds:

        private void PreventLinkerFromStrippingCommonLocalizationReferences()
        {
            _ = new System.Globalization.ChineseLunisolarCalendar();
            _ = new System.Globalization.GregorianCalendar();
            _ = new System.Globalization.HebrewCalendar();
            _ = new System.Globalization.HijriCalendar();
            _ = new System.Globalization.JapaneseCalendar();
            _ = new System.Globalization.JapaneseLunisolarCalendar();
            _ = new System.Globalization.JulianCalendar();
            _ = new System.Globalization.KoreanCalendar();
            _ = new System.Globalization.KoreanLunisolarCalendar();
            _ = new System.Globalization.PersianCalendar();
            _ = new System.Globalization.TaiwanCalendar();
            _ = new System.Globalization.TaiwanLunisolarCalendar();
            _ = new System.Globalization.ThaiBuddhistCalendar();
            _ = new System.Globalization.UmAlQuraCalendar();
        }

@Lelelo1
Copy link

Lelelo1 commented Jun 17, 2022

Can it be called in the forms project. Or do I need to call it from Android, iOS projects separately?

@BurkusCat
Copy link

@Lelelo1 I had included it in my platform specific projects. But you could try it in the Forms project and see if it prevents the crashes.

@Lelelo1
Copy link

Lelelo1 commented Jun 17, 2022

@BurkusCat
Ok. Thanks! I rather not want to risk more users to crash so I will place them in specific projects as well

@jpobst jpobst added the Area: Linker Issues when linking assemblies. label Oct 19, 2022
@jpobst
Copy link
Contributor

jpobst commented May 2, 2024

With support for Classic Xamarin.Android ended May 1st, 2024, this issue is likely no longer relevant.

If this still persists in .NET 8+, please open a new issue with updated information based on net8.0-android or greater. Please include a link to this issue for context.

@jpobst jpobst closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: Linker Issues when linking assemblies.
Projects
None yet
Development

No branches or pull requests

7 participants