Skip to content

Invariant Culture ISO Name is "Not a valid name" #10009

@Draco18s

Description

@Draco18s

The following:

_ = new CultureInfo(CultureInfo.InvariantCulture.TwoLetterISOLanguageName)

Will throw the error CultureNotFoundException: Culture name iv is not supported. (This happens with the ThreeLetterISOLanguageName "IVL" as well).

This seems... odd, given that _ = new CultureInfo(string.Empty) returns the CultureInfo.InvariantCulture object just fine.

This edge case is not indicated in the documentation.

Why is this important?

Suppose I create a list of CultureInfo that is supported by my application and include the InvariantCulture as a fallback (which would happen if the culture name supplied is an empty string, either accidentally or intentionally). If I serialize this list as cultureList.Select(c => c.TwoLetterISOLanguageName) and then attempt to load it via langNames.Select(n => new CultureInfo(n)), the invariant culture which will have serialized as iv then cannot be deserialized without edge-case detection to convert iv back to an empty string and will instead throw an error I could not have anticipated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.GlobalizationuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Draco18s

        Issue actions

          Invariant Culture ISO Name is "Not a valid name" · Issue #10009 · dotnet/dotnet-api-docs