Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How could I use the "CM" region in .NET 6?

I have a .NET 6 application. I am trying to run this code:

using System;
using System.Text;
using System.Globalization;
                    
public class Program
{
    public static void Main()
    {
        new RegionInfo("CM");
    }
}

I am getting this error:

Unhandled exception. System.ArgumentException: The region name CM should not correspond to neutral culture; a specific culture name is required. (Parameter ‘name’)
at System.Globalization.RegionInfo..ctor(String name)
at Program.Main()
Command terminated by signal 6

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is a fiddle.

The same code works fine in .NET 4.7.2. Also, I checked here that the "CM" is a valid ISO 3166 country code for Cameroon.

So, is this behavior a C# bug? I have an application where users can add countries. Now my application fails when the Cameroon is added. How could I fix or go around it?

It is a big application, so I can not just downgrade it to the .NET 4.7.2.

>Solution :

The error message isn’t saying that CM isn’t a valid culture name – just that it’s a neutral culture rather than a specific culture.

Apparently you need to specify a language/region combination, e.g. "fr-CM" for French (Cameroon) or "en-CM" for English (Cameroon).

I honestly don’t know why the behavior is different in .NET Framework to .NET 6, but the above appears to at least allow the constructor call to complete. Of course, you’ll need to check what the impact on the rest of the application is.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading