dotnet / dotnet/dotnet-api-docs

Invariant Culture ISO Name is "Not a valid name"

Open
#10,009 0 comments 0 reactions 0 assignees View on GitHub
area-System.Globalization Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

The following:

```csharp
_ = 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.