CultureInfo differs between .NET Core and .NET Framework
Asked Answered
T

1

6

There seems to be some difference for CultureInfo between .NET Core and .NET Framework. Is there any reason to this?

Example:

var italian = CultureInfo.GetCultureInfo("it").TextInfo.CultureName;

On .NET Core resolves to:

it

While it previously resolved to on .NET Framework to:

it-IT

This breaks some unit tests. Running this in two clean Console projects yield different results. Tried adding System.Globalization from Nuget without no difference in results.

Is there some configuration needed for this to be the same or have they broken CultureInfo altogheter?

Temblor answered 22/11, 2019 at 17:29 Comment(2)
The [documentation for CultureInfo] (learn.microsoft.com/en-us/dotnet/api/…) mentions the cultures available could vary by operating system. Maybe that's what is happening?Chavey
I would always try to work with subcultures. It is amazing how many differences are in big cultures with several subcultures. To globalize your code you should move into a subculture level code to avoid future problemsBracci
D
2

I confirm this behaviour, but Core is more conclusive.

You ask for culture "it", you get culture "it".

.NET Framework is adding more details and specifies a default subculture to it-IT.

If you ask for

var italian = CultureInfo.GetCultureInfo("it-IT").TextInfo.CultureName;

directly.

You will get the same result in both worlds.

To change that string should be a minor problem for your tests.

Dhu answered 22/11, 2019 at 17:52 Comment(1)
Except that being explicit with the info are also not working: var culture = new CultureInfo(new RegionInfo("sv-SE").Name); // Northern Sami in Core and Swedish in NET.Temblor

© 2022 - 2024 — McMap. All rights reserved.