14

I have an ASP.NET MVC application configured for Portuguese, on Visual Studio 2015. While debugging this application, I've set <customErrors mode="Off" />, but all errors are shown in Portuguese, and I want to see them in English.

I tried to set this in Web.config:

<globalization uiCulture="en-US" culture="en-US" enableClientBasedCulture="true" />

In Global.asax I tried:

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

and

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

I also uninstalled the Nuget package Microsoft.AspNet.Mvc.pt-br, no success.

This question is similar, but I need a solution that doesn't involve changing the machine's configuration or installed components, as that's not allowed in my workplace.

How can I make all error messages show in a specific language (in this case, English)?

Community
  • 1
  • 1
Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
  • 1
    Did you saw this one? http://stackoverflow.com/questions/209133/c-sharp-exception-messages-in-english And where are you setting this culture? Maybe you are setting up after the exception handling step in the pipeline – Fals Nov 23 '15 at 17:44
  • I hadn't see that, but that solution depends on `try/catch`, and I'm looking for a more generic solution, that can be configured for the whole application, specially for cases when your code isn't reached. But thanks. – Marcos Dimitrio Nov 23 '15 at 17:48
  • Possible duplicate of [Change language of error messages in ASP.NET](http://stackoverflow.com/questions/161486/change-language-of-error-messages-in-asp-net) – DavidG Nov 23 '15 at 17:54
  • You can setup this using CultureInvariant, but, It'll also override any localized and globalized configurations, for exemple, decimal convertion, what will make the application fail for Portuguese format. – Fals Nov 23 '15 at 17:57
  • @DavidG - I added an explanation for the duplicate flag. – Marcos Dimitrio Nov 23 '15 at 18:14
  • @Fals - I also tried `CultureInvariant`, but that didn't work either. I've added this to the question. – Marcos Dimitrio Nov 23 '15 at 18:14
  • Where (in which event) do you specify Culture/UICulture? – Mikhail Nov 23 '15 at 22:00
  • Can you see EN-US error messages in the other .NET (not this ASP.NET app) developed on this machine? – Mikhail Nov 23 '15 at 22:00
  • @Mikhail - Yes, I can. I managed to solve this problem, I posted it as an answer. Thanks all. – Marcos Dimitrio Nov 24 '15 at 16:47

2 Answers2

4

Today when I tried this again, to my surprise the messages were in English (almost, see below). I tried to reproduce the error I had yesterday, but I couldn't.

Perhaps it is just a matter of restarting (VS or the PC). I also kept working on the project at night on a different PC, but not on anything related with this issue, so I can't say it made a difference. All I have set up in Web.config is:

<globalization uiCulture="en-US" culture="en-US" enableClientBasedCulture="true" />

But still not everything was in English. While trying to reproduce the error, I forced a library load error, I used a DLL that requires Ninject to be installed. The error message was (emphasis mine on the translated part):

Server Error in '/' Application. Could not load file or assembly 'Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' or one of its dependencies. O sistema não pode encontrar o arquivo especificado.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

That part was supposed to be: The system cannot find the file specified.

In that case, I don't think there is much that can be done programmatically only.

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
-3

Uninstall the .net framework in the portugese version and reinstall the english version, that should do the trick.

Michael
  • 397
  • 2
  • 10