Why is my CurrentCulture en-GB and my CurrentUICulture en-US
Asked Answered
A

3

12

I have a C# application which has to run on machines with different culture settings. No problem I thought, it will just lookup on start up what the current culture is on the machine, and do everything for me. Well no, it would seam that something is not quite right.

I have a Windows XP machine with everything in Regional and Language options set to English US, yet when my application starts up it reports that my CurrentCulture is en-GB and my CurrentUICulture is en-US.

How can I get my program to just use whatever the PC is set to ?

This is a Windows Service application if it makes any difference.

Thanks

Anatase answered 13/11, 2009 at 23:8 Comment(1)
Does it have anything to do with the fact I am compiling the application on a machine with en-GB settings, but then executing it on a machine with en-US settings ? I just don't see where my en-GB is coming from, and my development machine is the only link.Anatase
S
6

A Windows Service usually doesn't run under your UserAccount and then it doesn't matter what your regional settings are. It's about the regional settings of the System account. I'm guessing you run a en-GB version of Windows, and the system account still uses that.

There are ways to get at that account, check SuperUser.

Sniperscope answered 13/11, 2009 at 23:54 Comment(1)
Yes, it was loaded as en-GB and changed to en-US. I think this will fix it. I will have a go now.Anatase
F
4

I believe the following is true:

  • CurrentCulture (which affects number and date formats) will reflect the regional settings of the account under which your application runs. You can change this easily with Control Panel / Regional Settings for the current user, and if you are an administrator also for the "default" user which is used for system accounts that are often used for Windows Services. To change the default user there's a "Use as Default" button somewhere.

  • CurrentUICulture will correspond to the language of the version of Windows you are using. For MUI versions, you can change this in Control Panel, but not for single-language versions.

Fates answered 14/11, 2009 at 0:32 Comment(0)
K
1

I know you can set what your invariant culture is as part of a build, but I was surprised when reading this that the culture of your build box became your invariant culture. Have you tried searching all files for en-GB just to be sure it is not defaulted somewhere?

Regardless, there is a workaround. If you want to override this with the O/S culture, you can get that in the following location and set your CurrentCulture and CurrentUICulture properties to it:

System.Globalization.CultureInfo.InstalledUICulture
Keelboat answered 13/11, 2009 at 23:34 Comment(2)
Thanks. I have checked that and I am not setting it anywhere, the only time I have used System.Globalization is just now whilst looking at what the CurrentCulture is set to. I am going to change my development PC to en-US and see if that solves it.Anatase
Oh, InstalledUICulture reports en-US, it's just CurrentCulture that still insists it's en-GB :-(Anatase

© 2022 - 2024 — McMap. All rights reserved.