dotnet / dotnet/dotnet-api-docs
Invariant Culture ISO Name is "Not a valid name"
- 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
Assessment
This issue has not been assessed yet.