Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
This static property should never return null, and currently it does, leading people from lots of places around the world unable to use our deployed app. We will of course work around this, but it needs to be fixed.
To reproduce, on an iPad go into Settings -> General -> International and change the region to Hong Kong SAR China. I've also had reports that Belgium is affected but have not yet substantiated.
Confirmed. "Hong Kong SAR China" and "Belgium" (likely others, but "Canada" was fine) presently returns null.
The construct_internal_locale_from_current_locale (in CultureInfo) internal call fails and Mono fallback to the InvariantCulture, which in turns returns a null RegionInfo.
iOS creates the locale from the current language + the international settings. So an English device using "Hong Kong SAR China" will return "en-HK".
Mono (and .NET) does not know about this (many "en-*" but only "zh-HK") and you can't create a "en-HK" CultureInfo on .NET (MS or Mono). That's why this presently fallbacks to an invariant culture (leading to the null RegionInfo).
Part of this situation can (and will) be fixed but, even then, the result won't always be 100% identical to iOS since the culture/region tables (both the types and values of data) inside Mono also differ from the ones from iOS.
I'm not sure what you need from RegionInfo but if it's available from NSLocale  then I suggest you to use it (both as an immediate solution and for consistency with iOS settings).
In our particular case, we're simply looking at the two-letter ISO country name of where the user is in order to present sensible defaults. The most important thing here is that RegionInfo.CurrentRegion is not null. As long as it returns something reasonably sensible, then the situation will be much improved.
I suggest somebody needs to create a table of mappings between iOS region settings and available .net cultures that is part of the spec for MonoTouch.
You can get the two letter code from:
and it will match the current iOS settings and works in existing versions of MonoTouch.
RegionInfo will be fixed but since it's definition (the properties it offers) and data (values) differs from iOS there will always be small mismatch between the two (but you can safely assume the two letters ISO code to be identical since it's the initialization key).
Thanks, that seems like a reasonable workaround for us. I wonder if it's safe to assume that NSLocale.CurrentLocale will never be null :)
Newer MonoTouch version (5.3+) will initialize RegionInfo.CurrentRegion from NSLocale.CurrentLocale.CountryCode if no Mono/.NET data is available for the current culture.
That should ensure RegionInfo.CurrentRegion won't ever return null on MonoTouch.