.NET 4.0 - CultureNotFoundException

扶醉桌前 提交于 2019-12-17 11:15:13

问题


I have migrated my ASP.NET MVC 2 project to VS 2010 + .NET 4.0. Now when i start the application i get a lot of "CultureNotFoundException" in IntelliTrace and Output/Gebug window :

A first chance exception of type 'System.Globalization.CultureNotFoundException' occurred in mscorlib.dll

I know what "A first chance exception" means, but when i try to debug(added "CultureNotFoundException" into Bebug/Exceptions[Thrown]) why ex. is thrown i got this detailed exception text:

System.Globalization.CultureNotFoundException occurred Message=Culture is not supported. Parameter name: name designer is an invalid culture identifier. Source=mscorlib ParamName=name InvalidCultureName=designer StackTrace: at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride) InnerException:

I wonder why .NET is trying to create CultureInfo with name "designer"?

Isn't it bug?


回答1:


I had a similar issue with the CultureName "UserCache". To resolve this I deleted all the folders from in here:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files



回答2:


For other people that have this problem, this is usually an exception that is ignored.

Go to the Debug menu -> Exceptions... and ensure that you have everything unchecked for the Exception list.




回答3:


This is actually by design in System.Web (at least up until .NET Framework v4.0), not necessarily the best approach, but it works.

You can find a more detailed description here, but it basically happens because ASP.NET checks every single folder to see if it contains satellite assemblies, and throws an exception otherwise.

Given that satellite assemblies live in folders with predictable names, one would wonder why they would decide to do this rather than only check folders that match the pattern, particularly since handling exceptions is rather expensive computationally compared to a simple conditional check.




回答4:


I was curious as to the cause to see if there was something I could personally do to eliminate this particular annoyance.

The Exception is a side effect of calling, "System.Web.UI.Util.IsCultureName(name)"

The first time it's called in my MVC3 application is in regards to a directory called "UserCache", which is in the same directory as several directories with the expected culture names "en-US", etc. .Net is trying to find Satellite directories for the application.

It's called multiple times, even relating to files that are culture files, "EditorLocalization.bg-BG.designer.cs" for example (actually all of these that are in App_GlobalResources). [ What the code does here is to take all the files in App_GlobalResources, and see if the file ends in a CultureName, again calling IsCultureName.

So there's nothing you can really do to avoid this... In production where the .cs classes won't be there, perhaps it won't happen. It certainly slows down startup quite a bit, though!

In any case, in my mind it's a total bug that Microsoft throws an exception inside, "IsCultureName().




回答5:


Go to the Debug -> Options in Visual Studio and check "Just My Code".




回答6:


I had a similar issue with the "CultureNotFoundException". To resolve this I had to delete all the folders from in here additionally:

%LocalAppData%\Local\Temp\Temporary ASP.NET Files

Deleting from here wasn't enough:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files



回答7:


I think it's the actual designer that messed things up. Try searching across your solution for "designer" string to see if any XML/HTML attributes have their values set to this string.




回答8:


I had this error message:

'ViewBag.XXXXX' threw an exception of type 'System.Globalization.CultureNotFoundException' dynamic {System.Globalization.CultureNotFoundException}

The inner message said:

The culture is not supported.\r\nParameter name: name\r\nneutral is an invalid identifier culture.

The problem was that there was an invalid definition of the assembly culture in the AssemblyInfo.cs file:

[assembly: AssemblyCulture("neutral")]

To fix it, just leave empty the "culture" parameter like this:

[assembly: AssemblyCulture("")]

That fixed the problem for me.




回答9:


I found that turning on "Enable Just My Code" in the Debugging section of the Visual Studio 2017 options worked for me. That just hides those exceptions, which are part of the normal operation of the framework.




回答10:


It seems as the problem was a bug in VS 2010 Beta 2.



来源:https://stackoverflow.com/questions/2116821/net-4-0-culturenotfoundexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!