Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CultureInfo values differ between applications for the same culture. Is this a bug?

Tags:

.net

asp.net

I have a strange issue occurring on my Windows 8 dev box. The following line of code results in two different values for the NumberFormat.NumberDecimalSeparator when comparing an ASP .NET application running Kentico and a console application (both running on .NET 4.0).

var culture = new System.Globalization.CultureInfo("en-ZA");
var separator = culture.NumberFormat.NumberDecimalSeparator;

The value of seperator:

  1. Kentico application: "," <- comma
  2. Console application: "." <- period

The correct output for my regional setting is a period.

How is this possible? When I first picked up a formatting issue for decimal numbers, I thought it may have been a Kentico bug, however this test indicates otherwise. How is it possible that a new instance of CultureInfo for a specific locale returns an instance that differs across applications?

like image 925
Rohland Avatar asked Sep 15 '25 23:09

Rohland


1 Answers

Jason Evans's comment pointed me in the right direction. See the link he posted: ASP.NET application doesn't reflect Regional settings

It turns out that regional settings are stored per user in Windows. This is something I should have been aware of. Updating the application pool to run as myself produced the same result across both applications.

To be fair, what is still confusing is how Network Service (the account the application pool was running under) came to have the incorrect value. I'm not even sure how I'd rectify that.

Edit:

If you need to update the regional settings for reserved accounts. You have two options.

  1. Control Panel > Regional Settings > Click the administrative tab and then select "Copy Settings". On the screen that launches, ensure you check "Welcome Screen and system accounts". Older versions of Windows are similar I believe.
  2. For the brave. Registry: HKEY_USERS > SID... > Control Panel > International. The security identifier for Network Service is: SID: S-1-5-20.

Ensure you restart the application pool for settings to take effect.

like image 111
Rohland Avatar answered Sep 17 '25 18:09

Rohland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!