System exception messages in VS2005 are given in the local language.
Sometimes it is nice, but often it is quite inconvenient - try looking up
MSDN or Google with a localized message!
So, after having received a rather obtuse message concerning a P/Invoke
error, I spent some time getting rid of this unwanted feature, and I wish to
share with you the results.
First, my solution: In the Load event of the main form, add:
Thread.CurrentThread.CurrentUICulture = new
System.Globalization.CultureInfo ("en-US");
Now, the explanation:
Visual Studio Debugger, How to: Find Out More About an Exception with the
Exception Assistant says quite clearly:
"Message: Message associated with the exception. This is displayed in the
language specified by the CurrentUICulture property of the thread that
throws the exception."
So it is a feature, albeit not well considered.
Where does CurrentUICulture come from?
The help at NET Framework Class Library, Thread.CurrentUICulture Property,
advises:
Application.Run(new UICulture());
But this is wrong, Application.Run does not take a culture parameter, and
the Application.CurrentCulture property does not affect the behavior of the
exception assistant - CurrentCulture and CurrentUICulture are not the same
thing! CurrentUICulture is a property of the thread, and is not affected by
either of the application CurrentCulture or the assembly
NeutralResourcesLanguage attribute. It is the language specified in the
control panel regional and language options.
The assembly Culture attribute may not be used: "Information on the culture
or language the assembly supports. This information should be used only to
designate an assembly as a satellite assembly containing culture- or
language-specific information. (An assembly with culture information is
automatically assumed to be a satellite assembly.)"
So we are left with dynamically modifying the thread CurrentUICulture.
In development I can make it depend on #if DEBUG. But what if a user in
another country gets a system exception using my software? I will get the
error message in his language and what could I do with it?
See
http://msmvps.com/blogs/calinoiu/arc...30/103426.aspx
JR