Why can I set a neutral culture for a thread? RRS feed

  • Question

  • According to the MSDN library documentation, setting Thread.CurrentCulture to a neutral culture should throw a NotSupportedException. And there used to be a time when I hit this exception. But today, it just works when it should not.

    I can set a culture with the name "en" and LCID 9 and IsNeutralCulture true to Thread.CurrentThread.CurrentCulture and it even saves that value. No exception, no implicit change.

    What's wrong here?

    Windows Forms and .NET 4.0, using Visual Studio 2010 on Windows 7. .NET 4.5(.1) may be installed, not sure.

    Sunday, May 4, 2014 4:12 PM


  • Argh, those stupid errors in the documentation. Okay, now I understand why it works now and hasn't in the past.

    My previous fix to this was to find the default non-neutral culture instead. I guess I should keep this work-around in case my code is used with older .NET versions...

    CultureInfo ci = new CultureInfo(culture);
    if (ci.IsNeutralCulture)
    	ci = new CultureInfo(ci.LCID | 0x0400);
    Thread.CurrentThread.CurrentCulture = ci;

    Sunday, May 4, 2014 4:47 PM

All replies