views:

1681

answers:

3

Hi all,

I'm running into a case where an ASP.NET application using the built-in globalization facilities is crashing.

On an ASP.NET page with the Culture="auto" directive, a user with a neutral culture as their browser language (such as "zh-Hans") will produce the following exception:

Culture 'zh-Hans' is a neutral culture. It cannot be used in formatting and parsing and therefore cannot be set as the thread's current culture.

at System.Globalization.CultureInfo.CheckNeutral(CultureInfo culture) at System.Threading.Thread.set_CurrentCulture(CultureInfo value) at System.Web.UI.Page.set_Culture(String value) at ASP.somePage_aspx.__BuildControlTree(somePage_aspx __ctrl) at ASP.somePage_aspx.FrameworkInitialize()

Any ideas? Garbage fed into the Culture/UICulture parameters generally seem to be ignored, but this case is causing an unhandled exception.

A: 

Can't you set the culture on begin request? (Note: asp.net requests can jump between threads so you need to hook into the thread moving as well.)

svinto
+1  A: 

First off, you might consider setting UICulture="auto" as well as Culture="auto" in your <%@ Page %> declaration.

Now, I am not seeing this repro on my .NET 4.0 (beta) install, so this might be a product bug in .NET 3.5.

Here's a great resource for learning about neutral cultures and the difference between UICulture and Culture: http://blogs.msdn.com/ddietric/archive/2008/02/05/yacvcp-yet-another-currentculture-vs-currentuiculture-post.aspx

Hope that's helpful.

Andrew Arnott
+3  A: 

I was having the same problem and after bonking my head against a wall for a while found the answer right under my nose.

The issue I had was in not understanding the difference between CurrentCulture and CurrentUICulture. The difference being CurrentCulture is used to format dates, numbers and perform sorting, CurrentUICulture is used to lookup culture specific strings from a resource.

I had some code that looked like

return input.ToString("C", System.Globalization.CultureInfo.CurrentUICulture);

when it should be been

return input.ToString("C", System.Globalization.CultureInfo.CurrentCulture);

When you start trying to format culture specific items with a non-specific culture you will get the System.NotSupportedException.

marshall
This may not be the exact same problem but you should be looking for some code where you are trying to assign a neutral culture via CurrentUICulture to something expecting a more specific culture that you can access via CurrentCulture.
marshall