Culture is not supported. Parameter name: name US is an invalid culture identifier
Solution 1
From CultureInfo(string)
constructor documentation;
For a list of predefined culture names, see the National Language Support (NLS) API Reference
Also from CultureInfo.TwoLetterISOLanguageName
Property
For example, the two-letter abbreviation for English is
en
.
There is no US
defined but there is en
(if you really have to use two letter name) which you can use it. All of them defined in ISO 639-1 standard.
var cultureInfo = new CultureInfo("en");
Solution 2
Argument of CultureInfo
constructor is not a ISO-3166 code, but predefined culture name
From MSDN article concerning CultureInfo
:
For a list of predefined culture names, see the National Language Support (NLS) API Reference at the Go Global Developer Center.
In the reference mentioned there is no us
culture, but there is en-US
, so you have to use ut.
Solution 3
Because US
is not a valid culture name whereas FR is. CultureInfo's constructor doesn't accepts country code as parameter. It expects the "Culture Name".
Refer the table in this msdn page for valid culture names.
Comments
-
Gianluca Ghettini over 4 years
I tried to use a ISO-3166 two letter country code to create my C# culture info object to format my
datetime
objects according to the locale.If I try:
var cultureInfo = new CultureInfo("FR");
it works fine, if I try:
var cultureInfo = new CultureInfo("US");
it throws an exception:
Culture is not supported. Parameter name: name US is an invalid culture identifier.
The funny thing is that "US" is a valid ISO-3166 country code.
-
Gianluca Ghettini over 8 yearsok. so basically the CultureInfo constructor doesn't accept directly ISO-3166 country codes...
-
Soner Gönül over 8 years@GianlucaGhettini It can accept some of them but not all. Those are different standards.
-
Soner Gönül over 8 years@GianlucaGhettini Yes. You can create your own
KeyValuePair<string, string>
for example. -
Gianluca Ghettini over 8 yearsOk thanks. Answer accepted. Any advice on where to find such mapping? I mean, can't believe I'm the first one to face such problem....