44

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 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

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
serhio
  • 28,010
  • 62
  • 221
  • 374
  • 2
    I have the same problem with german with english visual studio and even the compiler erros are localized in german. (Which makes googling them difficult) – Christian Rodemeyer Jan 19 '10 at 09:16
  • @Christian: See the http://stackoverflow.com/questions/721337/forcing-english-language-exceptions-in-net-framework maybe this will help you... – serhio Jan 19 '10 at 09:18
  • possible duplicate of [C# - Exception messages in English?](http://stackoverflow.com/questions/209133/c-sharp-exception-messages-in-english) – Andrej Adamenko Sep 01 '14 at 19:36

7 Answers7

15

You could set the current culture to English only in debug builds :

#if DEBUG
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
#endif
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
  • 10
    Wouldn't that make debugging unreliable? Other parts of the project might depend on the France culture. – Kobi Jan 19 '10 at 09:16
  • 1
    @Thomas: yes, but this change will affect all other code users. If my project manager is a old french man he will decapitate me for that :) – serhio Jan 19 '10 at 09:17
  • 2
    @Kobi : most culture-specific behavior like date/time/number formatting depend on the CurrentCulture, not the CurrentUICulture. CurrentUICulture only affects which resources are used. If there are no satellite assemblies for resources in cultures other than French, it will fall back to the default culture anyway – Thomas Levesque Jan 19 '10 at 10:20
  • 2
    @serhio: He probably would not decapitate you if you make the UI culture a config setting and configure it only in your personal build to be "en-US". – Dirk Vollmar Jan 19 '10 at 11:57
  • 1
    @divo: yeah, maybe, but I am sure he will not accept as well changes in the actual project only because I want my exceptions in English. – serhio Jan 19 '10 at 12:13
6

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.

IS4
  • 11,945
  • 2
  • 47
  • 86
5

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.

Chiramisu
  • 4,687
  • 7
  • 47
  • 77
Stanislav Berkov
  • 5,929
  • 2
  • 30
  • 36
  • 1
    @Hi-Angel No, it was closed as "not fixed". Could not find any new entry on https://developercommunity.visualstudio.com/ – Louis Somers Sep 07 '17 at 12:36
  • @LouisSomers I just remember, it was a sarcasm. So subtle though that I didn't see it myself. It probably was a reference to MS ignorance of requests and bugs in general *(see e.g. Skype problems)*. – Hi-Angel Sep 07 '17 at 15:54
  • @Hi-Angel I'm doing another attempt at the [DotNet repository on GitHub](https://github.com/Microsoft/dotnet/issues/474#issue-256175151). Unfortunately I don't have time to fix it myself and ask them to merge it in, but maybe someone else does? – Louis Somers Sep 08 '17 at 08:20
  • @LouisSomers sorry, I don't. I have a list of my own things too: adding a few important features to LibreOffice *(I'm even thinking of a kickstarter project; it's something I'm looking into ATM)*, primary clipboard to a Wayland compositor beside Gnome, reading i3-like configs in enlightenment… Just out off top of my head. And even this seems like gonna take veeery long time. – Hi-Angel Sep 08 '17 at 09:05
  • Voting has moved here:https://developercommunity.visualstudio.com/idea/626664/get-rid-of-localised-exception-messages-by-choice.html (chances to fix it are still pretty low) – Shaedar Oct 02 '19 at 14:25
4

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.

serhio
  • 28,010
  • 62
  • 221
  • 374
3

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.

tomsv
  • 7,207
  • 6
  • 55
  • 88
2

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.

KuN
  • 1,143
  • 18
  • 23
0

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.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
  • what exactly do you mean my "current UI language"? My OS is French one(by e.g. the "Start" button name is "Démarrer"), so by default `CultureInfo.CurrentCulture.Name == "fr-FR"` – serhio Jan 19 '10 at 09:51
  • In ControlPanel I changed the "Regional and language options" => "Standards and formats" to be "English US", but this didn't help. – serhio Jan 19 '10 at 09:58
  • I'm talking about the one set in the International settings in the Control Panel (http://www.guidebookgallery.org/pics/gui/settings/international/winxppro-1-1.png). EDIT I saw now your comment... I don't know, AFAIK it should work like that... – Matteo Italia Jan 19 '10 at 09:58
  • @Matteo: you are partially right. I changed the "Standards and formats", and this really changed the **CurrentCulture**, but NOT changed the Thread's **CurrentUICulture** : *CurrentCulture* changed in **en-US**, but *Thread.CurrentThread.CurrentUICulture* remained **fr-FR**. – serhio Jan 19 '10 at 10:11
  • I think you can only change UICulture in Regional Settings if you have an MUI version of Windows. I think the setting is Regional and Language Options / Languages / Language used in menus and dialogs (on XP). – Joe Jan 19 '10 at 15:56
  • You're right: although the regional settings always had effect on the language of the resources retrieved by the unmanaged APIs, the CurrentUICulture is said on the docs to be initialized by default to the value provided by GetUserDefaultUILanguage, whose doc says that "If MUI is not installed on the operating system, the function retrieves the default computer user interface language." Anyhow, now that we know how it works, you could just set CurrentUICulture to the CultureInfo of CurrentCulture. --- EDIT --- I saw just know that you figured it out by yourself. :P – Matteo Italia Jan 19 '10 at 17:50
  • @Matteo: yes, but you know, this didn't help me much as I can't(don't want) change the solution code for that, because this will affect not only me. – serhio Jan 21 '10 at 08:47
  • Making the descriptions of the exceptions match the preferred language of the user for me it's a bonus also for the end users. – Matteo Italia Jan 21 '10 at 19:33
  • FWIW, on Windows 7 (English) if you install optional language packs then you can change the "display language" on a per-user basis (essentially, MUI is built-in). This is probably the easiest way to handle this short of just adding an option to the program. – Shog9 Jan 26 '10 at 17:42
  • I didn't try Windows 7, but as far as I remember the .NET Framework is localized separately from Windows, and the various language packs are freely installable on every machine, so setting the CurrentUICulture to the desidered one should work on every machine that has the needed language pack (usually on every machine there's the "normal" Framework in English plus the local language pack). – Matteo Italia Jan 26 '10 at 22:45