Force exceptions language in English
My Visual Studio 2005 is a French one, installed on a French OS. All the exceptions I receive during debug or runtime I obtain also in French.
Can I however do something that the exceptions messages be in English? For goggling, discussing etc.
I tried the following:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
throw new NullReferenceException();
obtained
Object reference not set to an instance of an object.
This is, surely, cool... but, as I work on a French project, I will not hardcode forcing Thread.CurrentUICulture to English. I want the English change to be only on my local machine, and don't开发者_JS百科 change the project properties.
Is it possible to set the exceptions language without modifying the code of the application?
In VS 2008, set the Tools -> Options -> Environment -> International Settings -> Language to "English" wnd throwing the same exception obtain the ex message en French, however: alt text http://lh4.ggpht.com/_1TPOP7DzY1E/S1V62xcvHAI/AAAAAAAAC7o/ckLDVFPKh5Y/s800/exception.png
You could set the current culture to English only in debug builds :
#if DEBUG
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
#endif
For the good of all future users of your application, place this to the Main method:
CultureInfo.DefaultThreadCurrentUICulture = Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
It will save them a good lot of trouble finding the English equivalent of a a badly translated error message.
This is known problem. Please vote for fix here: Exception Handling / Error Logging in English
Old Link on Microsoft Connect which has since been decommissioned.
Finally a "sharp" solution could be the following:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
#if DEBUG
// Add this; Change the Locales(En-US): Done.
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
#endif
Application.Run(new Form1());
}
However I'd like a solution without modifications in the project code.
From MSDN:
The CurrentUICulture property will be set implicitly if an application does specify a CurrentUICulture. If CurrentUICulture is not set explicitly in an application's code, it is set by the GetUserDefaultUILanguage function on Windows 2000 and Windows XP Multilingual User Interface (MUI) products where the end user can set the default language. If the user's UI language is not set, it will be set by the system-installed language, which is the language of the operating system's resources.
If an application is Web-based, the CurrentUICulture can be set explicitly in application code to the user's browser accept language.
Uninstall the French language pack:
Start - Control Panel - Programs and Functions - Microsoft .NET Framework (4 Client Profile) Language Pack FRU - Uninstall
You may need to repeat the uninstallation for each version of .NET Framework that you find there.
For any Win8/8.1 users facing this issue, installing the English Language Pack and make it the Windows display language seems to be only easy way to resolve it as Win8 has .net framework built in its core.
Probably the same for Win10.
I didn't try, but according to the documentation that property should be set by default to the current UI language, that is set in the control panel. So it should work correctly automagically according to your international settings.
精彩评论