Skip to content

CultureInfo.GetCultureInfo("root") is an accepted but incomplete culture which can raise NullReferenceException on internals #132429

Description

@rjgotten

Description

"und" is the correct BCP-47 tag for the "undetermined language" and maps correctly to CultureInfo.InvariantCulture when using CultureInfo.GetCultureInfo("und").

"root" is the alternative moniker used by CLDR.
When using CultureInfo.GetCultureInfo("root") it does not throw a CultureNotFoundException.
Rather it returns an incomplete unknown culture with LCID 4096.
And if one attempts to read NumberFormat off of it:

> System.Globalization.CultureInfo.GetCultureInfo("root").NumberFormat
System.NullReferenceException: Object reference not set to an instance of an object.
  + System.Globalization.NumberFormatInfo.InitializeInvariantAndNegativeSignFlags()
  + System.Globalization.CultureInfo.get_NumberFormat()

Reproduction Steps

Open any C# repl and execute:
System.Globalization.CultureInfo.GetCultureInfo("root").NumberFormat

Expected behavior

Either CultureInfo.GetCultureInfo("root") throws a CultureNotFoundException or it produces an actual intact culture.

Actual behavior

CultureInfo.GetCultureInfo("root") is accepted as a valid, recognized culture and does not throw a CultureNotFoundException - however what it produces is in fact not an actual intact culture.

Regression?

No response

Known Workarounds

No response

Configuration

.NET version: .NET 10
OS: Windows 11

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions