The exception text is forwarded based on the OS language. (Anyway, the exception of .NET itself)

Is it possible to make it so that throwing an error was always in 1 language ignoring the language of the executable environment?

  • 2
    And the desired language is exactly installed on all PCs? - Andrei NOP

2 answers 2

The language of the exception text depends on the CurrentUICulture flow in which the exception occurred. Code

 try { await Task.Run(() => { Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE"); throw new ArgumentException(); }); } catch (ArgumentException ex) { Console.WriteLine(ex.ToString()); } 

produces text

Der Wert liegt außerhalb des erwarteten Bereichs.


To set the language for all threads at the same time, you can write in the Main function:

 var ci = CultureInfo.GetCultureInfo("de-DE"); CultureInfo.CurrentUICulture = ci; CultureInfo.DefaultThreadCurrentUICulture = ci; 

    This can be done only for a specific project, and only in the code

      #if DEBUG Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); #endif 

    will give you English messages when debugging