ASP.NET Globalization: Culture="auto" page directive with neutral culture crash?
Asked Answered
Q

3

7

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.

Quach answered 21/8, 2009 at 23:32 Comment(0)
D
3

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.

Dennard answered 31/8, 2009 at 20:58 Comment(0)
M
6

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.

Mcauliffe answered 3/11, 2009 at 3:46 Comment(1)
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.Mcauliffe
D
3

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.

Dennard answered 31/8, 2009 at 20:58 Comment(0)
H
2

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.)

Holbein answered 26/8, 2009 at 18:49 Comment(1)
hi Andrew Arnott. i placed culture="auto" uiculture="auto" in my <%@Page %>.Even also getting same exception as 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. this exception in single page remaining all pages working fine.------Please help meTenatenable

© 2022 - 2024 — McMap. All rights reserved.