Skip to content

new RegionInfo("NO").NativeName returns different strings depending on the capitalization of the country code #39991

@castholm

Description

@castholm

Norway has two official native names in its two official written standards; Norge in Bokmål and Noreg in Nynorsk.

When initializing a new RegionInfo with a Norwegian country code it will have a different value for its NativeName property depending solely on whether you capitalized the country code or not.

The official documentation for the RegionInfo(string) constructor specifies that case is not significant.

What's even worse is that depending on which capitalization you use the first time you initialize a RegionInfo instance the results will be cached and be returned on subsequent initializations of instances regardless of capitalization.

Quick sample code that demonstrates the issue:

using System;
using System.Globalization;

namespace ConsoleApp1
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(new RegionInfo("NO").NativeName);
            Console.WriteLine(new RegionInfo("no").NativeName);
        }
    }
}
Noreg
Noreg

If we change the order we initialize the instances, we get a completely different output:

using System;
using System.Globalization;

namespace ConsoleApp1
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(new RegionInfo("no").NativeName);
            Console.WriteLine(new RegionInfo("NO").NativeName);
        }
    }
}
Norge
Norge

It is expected that both capitalizations of the country code should return the same NativeName regardless of which is used first.

.NET Core version: 3.1.302
OS: Windows 10, version 2004, build 19041.388

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions