Search code examples
c#asp.netglobalization

System.Global.CultureNotFoundException on some systems but not others


We had a request to add Haitian Creole resx files to our app from a customer. We got the translations and I went to plug them in, but I immediately found there's scant browser support for ht as a language/locale code. Chrome wouldn't let you enter it anywhere. IE 11 let you enter it as a custom code. Only Edge and Firefox offered it up.

But the perplexing part to me is that when I go to a debug system with those resx files plugged in, and I hit the site with a browser, I get a System.Global.CultureNotFoundException on the following line:

CultureInfo ci = CultureInfo.CreateSpecificCulture(cultureName);

But if I go to a different system with our release build that doesn't have the resx files, there's no error. Obviously I don't get any Haitian Creole translations either, but that same like of code does not blow up when presented with ht.

I've executed the same powershell command to list the supported languages on both systems, and Haitian Creole is not on the list of either system.

[system.Globalization.CultureInfo]::GetCultures('AllCultures')

Is it some release mode build thing to quietly fall back to the system language when a browser presents an unrecognized code? Near as I can tell the only differences between my test systems is release mode/no ht resx and debug mode/with ht resx.

I don't get why I'm not getting the same exception in both places...

Thanks


Solution

  • It would appear that the System.Global.CultureNotFoundException exception occurs when your app has resx files for the locale code but the system at wide doesn't recognize it.

    Taking advantage of the IE 11 feature to enter any odd custom code you want, I added xx-xx and put it at the top of my list. Of course, I don't have any resx files for xx-xx.

    Requests to the site with an Accept-Language header leading with xx-xx do not throw a System.Global.CultureNotFoundException exception; it just quietly moves on to the next one down in the list.

    The difference between my dev site and the other release builds was that my dev site had .ht.resx files in the build while the other qa sites did not