Description
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.