C# CultureInfo.GetCultures returns a (nearly) empt

2019-07-19 05:41发布

问题:

Windows 8.1 Pro, Visual Studio 2013, .NET Framework 4.5.2

Here is the code:

var cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
Console.WriteLine("Culture count: " + cultures.Length);

Here is the output:

Culture count: 2

The two cultures are zh-CHS and zh-CHT which are added in the CultureData.GetCultures method. The other cultures are supposed to be returned by CultureData.nativeEnumCultureNames but it appears that this is returning an empty array.

This behavior appears to be limited to a single workstation. I've tried the same code on other computers and am getting normal results. How would I go about fixing this? I've attempted re-installing the .NET framework with no success.

Edit 1: This only affects .NET 4/4.5. If my project targets .NET 3.5, it works, returning 311 cultures.

回答1:

Check to see if the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\ExtendedLocale is present. If it is missing, there is a known issue that can be worked around by adding this key.