4

I'm trying to get RegionInfo object by the country name. I've come up with this code:

 var regions = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(x => new RegionInfo(x.LCID));
 var regionInfo = regions.FirstOrDefault(region => region.EnglishName.Contains(englishCountryName));

and it works fine on my machine. But when I deployed it on Azure App Service it returns null for Czechia.

So I tested it:

//My machine
new RegionInfo(1029).EnglishName //returns Czechia
//Azure
new RegionInfo(1029).EnglishName //returns Czech Republic

As it turned out, Czech Republic changed it's name in 2016 so why Azure displays "old" name? How to make this solution culture-independent?

bineros
  • 51
  • 4

1 Answers1

1

With country name potentially changing, you are better off using one of the ISO codes.

If you cannot use ISO codes based on your input, you can take control of mapping English language input to ISO code using something like ISO3166 NuGet package. I see that the current version does not seem to be up to date either, but if you implement it, at least you will get a consistent value.

Fabo.sk
  • 116
  • 1
  • 10