Show all exceptions in English

I am using a try ... catch block in main.

When I install the next

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

This eliminates all exceptions and prints them in English.

But this does not work for many APIs inside, especially for exceptions caught as directory access files. Is there anything else that needs to be done?

So the main problem is that Execption

 System.Net.Sockets.SocketException (0x80004005): 

The message after that does not appear in the locale set

+4
source share
3 answers

I was able to do this using Win32 FormatMessage Code

 [DllImport("Kernel32.dll", SetLastError=true)] static extern uint FormatMessage( uint dwFlags, IntPtr lpSource, uint dwMessageId, uint dwLanguageId, ref IntPtr lpBuffer, uint nSize, string[] Arguments); 

and installing langid as english!

+1
source

This problem can be partially solved. Framework exception code loads error messages from its resources based on the current locale of the stream. In the case of some exceptions, this happens during access to the Message property.

For these exceptions, you can get the full version of the message in English by briefly translating the language standard of the stream into en-US during its registration (first save the user's original language and immediately restore it).

Doing this in a separate thread is even better: it ensures that there are no side effects.

Link: Exclusion Messages in English?

0
source

Do not select a culture for the user. Let him do it himself.
There are rare cases when you need to use a predefined culture, but in most cases it is the user's business - which culture to use.

0
source

Source: https://habr.com/ru/post/1437759/


All Articles