Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top