15

Out of the blue our Azure web app is spewing out errors regarding a Culture that is not supported. We load up a list of countries to show on the front page but this is suddenly giving errors. The same code is used on other various web apps as well and they aren't having the problem.

The following code gives a problem.

 private List<SelectListItem> Countries()
        {
            RegionInfo country = new RegionInfo(new CultureInfo("nl-BE", false).LCID);
            List<SelectListItem> countryNames = new List<SelectListItem>();
        foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
        {
            country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);
            countryNames.Add(new SelectListItem() { Text = country.DisplayName, Value = country.DisplayName });
        }

        return countryNames.GroupBy(x => x.Text).Select(x => x.FirstOrDefault()).ToList<SelectListItem>().OrderBy(x => x.Text).ToList();
    }

I placed a try-catch in the for-each so I can pinpoint the cultures that are giving errors. The following cultures are suddenly returning errors:

<errors>
<LCID>4096</LCID>
<Name>ar-001</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>el-CY</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>en-BB</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>en-BS</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>en-HK</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>en-NL</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>en-SE</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>es-419</Name>
</errors>

Can someone help me with this issue? I can't seem to make sense on why this web app is suddenly giving these errors.

Kevin Cloet
  • 2,956
  • 1
  • 19
  • 36
  • 1
    I am having the exact same issue as of a few hours ago! I strongly suspect it is a Microsoft Azure update/change causing this as we haven't deployed to our web site for weeks. I get the following error nearly all the time (sometimes I can actually access the web site say 1% of the time): Culture is not supported. Parameter name: culture 4096 (0x1000) is an invalid culture identifier. – hamish Jan 26 '17 at 02:50
  • Please try to leverage this powershell command `[system.Globalization.CultureInfo]::GetCultures('AllCultures')` to retrieve the supported cultures by accessing "Debug console > PowerShell" within [KUDU](https://blogs.msdn.microsoft.com/benjaminperkins/2014/03/24/using-kudu-with-windows-azure-web-sites/) . Then try to find whether you could find the above cultures. – Bruce Chen Jan 26 '17 at 03:44
  • That command didn't work for me (threw an error) but this one did: [system.Globalization.CultureInfo]::GetCultures('FrameworkCultures') and it seemed to return all the cultures I would expect to be installed in a MS Windows server/VM. – hamish Jan 26 '17 at 03:54
  • 2
    I have submitted a technical support ticket with Azure and they are looking into my issue. – hamish Jan 26 '17 at 04:02
  • BTW: "AllCultures" shows all of the cultures that .Net can find, including the ones from the OS. "FrameworkCultures" restricts the list to those included in .Net. Typically I'd recommend "All" cultures, as, for most apps without an LCID dependency, that is more interesting. Framework only might be an acceptable workaround in some cases like this. – Shawn Steele - MSFT Jan 26 '17 at 18:08
  • Note that running `[system.Globalization.CultureInfo]::GetCultures('AllCultures')` from Kudu console worked fine for me. @hamish I think the reason it didn't work for you is that Bruce's note includes some control characters that messes it up (assuming you copy/pasted). But it does work. – David Ebbo Jan 26 '17 at 19:27
  • Thanks @david-ebbo. Microsoft support have advised me that Microsoft have stopped the rollout of the update across their Azure servers whilst they investigate how best to resolve the issue. In the meantime, as I don't have access to the code in 3rd party assemblies that are making the failing calls, I have found an Azure server that hasn't been updated yet by the rollout and redeployed our application there and it is working just fine as it was before. – hamish Jan 26 '17 at 21:32
  • 4
    **Important**: please read [this post](https://blogs.msdn.microsoft.com/appserviceteam/2017/03/07/custom-cultures-coming-soon-to-azure-app-service/) relating to upcoming changes. – David Ebbo Mar 08 '17 at 20:25
  • 1
    Solution contained in that blog post solved my issue, thanks @DavidEbbo :-) – Rui Jarimba Apr 07 '17 at 10:30
  • Thankyou! @DavidEbbo – Kumar Garapati Apr 07 '17 at 20:06
  • @DavidEbbo's post says: "Using the LCID culture identifier property of the CultureInfo object instance instead would not be recommended" – OzBob May 16 '17 at 02:51

2 Answers2

18

Almost all of the new locales in Windows are not assigned explicit LCIDs - because there is not enough "room" for the thousands of languages in hundreds of countries problem. They all get assigned 0x1000.

In this case, I think a changing LCID to name might work for you:

country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);

to just use the culture name:

country = new RegionInfo(cul.Name);

Of course, any other use of LCID would also need to recognize the culture name instead.

We actually recommend that RegionInfo be constructed with a full culture name since that is more explicit than just the region name.  RegionInfo has some properties that "depend" on the languages, such as the DisplayName. es-US and en-US provide Spanish or English strings for "United States", for example.

Hope that helps,

-Shawn

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • https://social.msdn.microsoft.com/Forums/en-US/963f02d1-bf04-430a-ab51-9c3fc0462e63/cultures-not-supported-on-azure-webapps?forum=windowsazurewebsitespreview forums reference of list of unsupported culture by LCID. That 'need' Name. – OzBob May 16 '17 at 05:46
4

I confirm that these are new cultures that were just added in Azure App Service, and evidently it was done in a way that creating a RegionInfo fails. The simplest repro is:

var culture = new CultureInfo("en-HK", false).LCID;
var region = new RegionInfo(culture);

And that fails with:

Unhandled Exception: System.Globalization.CultureNotFoundException: Culture is not supported. Parameter name: culture 4096 (0x1000) is an invalid culture identifier. at System.Globalization.CultureData.GetCultureData(Int32 culture, Boolean bUseUserOverride) at System.Globalization.RegionInfo..ctor(Int32 culture)

We are investigating further. In the meantime, catching exceptions and ignoring cultures where that fail is the recommended workaround.

David Ebbo
  • 42,443
  • 8
  • 103
  • 117