PC Review


Reply
Thread Tools Rate Thread

Localized Exception Messages in WinForms

 
 
JR
Guest
Posts: n/a
 
      28th Apr 2007
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Localized Exception Message Luthgers, John Microsoft Dot NET Framework 3 16th Aug 2008 11:39 PM
localized exception messages leibnizster Microsoft Dot NET Framework 5 22nd Feb 2007 06:00 PM
localized exception messages leibnizster Microsoft ADO .NET 5 22nd Feb 2007 06:00 PM
Localized exception messages perboddum Microsoft Dot NET Compact Framework 4 28th Dec 2005 07:50 PM
Exception messages in localized application james@microsec.co.uk Microsoft Dot NET Framework 2 14th Jan 2005 09:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:31 AM.