views:

1042

answers:

5

How do I make my application always use English when displaying win32/.net exceptions messages?

I got this message, it looks like someone used babelfish to translate it (it's Swedish): "System.ComponentModel.Win32Exception: Programmet kunde inte starta eftersom programmets sida-vid-sidakonfiguration är felaktig."

Extremely unhelpful, and Google had a whopping 4 hits for it, none of them helpful. So I have to guess what the original message was and google that. (It's was: "The application has failed to start because its side-by-side configuration is incorrect.")

This time it was fairly simple to find out what the original error message was, having the message in English from the start would of course save me time.

So how do I do that?

+3  A: 

You can try setting Thread.CurrentThread.CurrentUICulture and/or .CurrentCulture to CultureInfo("en-US").

Alexander Kojevnikov
If you change CurrentCulture, won't that change decimal separators, string sorting, currency symbols, date formats etc? Which will seriously annoy your foreign users
MarkJ
Here is the full line:System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
epotter
Is there another possibility than changing the Culture, since that may be set by the application for translation purposes. The exceptions however shouldn't be translated. Are there any packages to remove on the .Net installation??
Juri
A: 

If it's an ASP.NET application, you can set the UI language in web.config (*):

<system.web>
    <globalization ... uiCulture="en-US" ... />
</system.web>

For other applications, the current user's regional settings are used by default, and you have to explicitly override it - e.g. Thread.CurrentUICulture = new CultureInfo("en-US").

(*) caveat - if an error in the config file results in an exception being thrown before the element is processed, you'll get the default uiCulture.

Joe
+1  A: 

Forcing exceptions to display in a different language seems a bit harsh on the user... can you display an error code along with the message? Then the user will get something they can understand, and you can look up the error code for the translated version.

I'm not a .net guy so I don't know if this is possible, just an idea.

MrZebra
I'm the recipient of that message, not the user, who probably would not understand the error message even if it was in their language.No user should ever see an exception thrown, so I have to catch it and fix it. I have to translate it from Swedish to English before I can understand it.
Nifle
A: 

How do I make my application always use English when displaying win32/.net exceptions messages?

First of all, don't show win32/.net exception messages to users. You should handle exceptions rather than showing them to user.

By default exception messages will be shown in current's UI language (if appropriate language pack is installed, otherwise they fallback to English). You can change exception messages changing Thread.CurrentThread.CurrentUICulture property, however it will affect the whole GUI of your app.

aku
This application is still in testing, so I think a few exceptions shown to the tester is OK. His purpose is to find them after all. I use an external csv language file for all my text strings so hopefully changing the UICulture will not affect the user.
Nifle
+2  A: 

All the more reason why the exceptions shouldn't be translated (badly). When logging exceptions, it makes muc more sense to do it in a single language. I can't believe Microsoft didn't think of a way to do this other than UICulture, which is basically a non-option :(