Tutorial :Forcing English language exceptions in .NET framework



Question:

While working with ASP.NET MVC, I have noticed that exception messages issued by the .NET framework installed on my System are in German. I'd really prefer English messages, so I can post them on SO.

I know this has been asked before on SO, but strangely enough none of the suggested workarounds seem to work in my case. I have already tried the following:

  • switching my Windows system to an English locale and restarting Visual Studio
  • Setting Tools -> Options -> Environment -> International Settings -> Language to "English"
  • setting the thread locale to English right before the exception is thrown as follows:

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture ("en-US"); Thread.CurrentThread.CurrentUICulture=new CultureInfo("en-US");

    //call my faulty method...

So, how can I make the .NET framework issue English language exception messages? And is there any approach that does this on a per-solution or even system-wide basis?

Edit: The exception is thrown while excuting my unit tests. I am not sure if this is the reason setting the thread's culture had not effect.


Solution:1

As I just found out, the problem was indeed related to having a different test project. While I have tried setting the UI language to English in my actual project, I did not do the same in the test project, which is why the exception messages were still in German when looking at the test results.

Setting the UI language in the test method right before the exception is thrown did the trick for me.


Solution:2

Uninstall the German language pack:

Start - Control Panel - Programs and Functions - Microsoft .NET Framework (4 Client Profile) Language Pack DEU - Uninstall (Deinstallieren)

You may need to repeat the uninstallation for each version of .NET Framework that you find there.


Solution:3

Have you tried setting the UI culture to "en" in web.config? More info here.


Solution:4

Apparently all the framework exception messages are bound to the installed OS language. So unless you install an English version of Windows The .Net framework exceptions won't appear in English. Even though it seems strange that setting the CurrentUICulture to "en-US" does not help, I used this sort of workaround hack to have English messages on my Dutch Windows OS.


Solution:5

Actually doesn't exists a good solution for this, vote on Connect for this approach

https://connect.microsoft.com/VisualStudio/feedback/details/591839/exception-localization-in-app-config-and-web-config


Solution:6

I've tried the following changes in the web.config and it helped:

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


Solution:7

Have you tried switching the culture immediately prior to reading the exception text? It may be that the localization occurs when you access the message - as opposed to when the exception object is created.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »