.NET 4.0 - CultureNotFoundException
Asked Answered
J

11

52

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?

Jacobian answered 22/1, 2010 at 11:18 Comment(0)
J
-4

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

Jacobian answered 27/2, 2010 at 14:7 Comment(3)
Wow, that's an old version of VS.NET :-)Wham
That is actually incorrect mate, this is a bug in System.Web, see my reply.Affluent
This is not a VS 2010 bug. It is still a problem in the latest update of 2019Bothersome
C
60

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
Canales answered 21/2, 2013 at 9:51 Comment(3)
see #869380 for a similar problem and explanation with a folder "uploads"Hardwick
kill iisexpress.exe if files are locked to delete.Johen
What is app is in azure? how should i do this?Hunchbacked
R
26

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.

Rhodos answered 17/1, 2011 at 15:45 Comment(5)
Interesting, how this error started from no where. After taking your suggestion to uncheck the Exception, I noticed that instead of the dual list I normally see there is only one list. idk if that helps get to the bottom of how this comes about.Doublet
not sure wjy I now have this problem when try to debug... I not changed anything and from one moment to another it starts to fail, at least I can continue debugging now,thanks for sharing this tip, it saves me!Shona
Depending on your config it can also be repaired by enabling "Just my Code" option under Options > Debugging > General > "Enable Just My Code"Literate
Ignoring the problem is NOT the solution.Bcd
This doesn't help if it's some library I use that gets the exception.Frutescent
A
20

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.

Affluent answered 25/11, 2013 at 16:19 Comment(0)
P
16

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

Paste answered 10/6, 2011 at 4:37 Comment(0)
M
9

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

Micromillimeter answered 15/10, 2018 at 12:29 Comment(0)
C
4

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.

Caribbean answered 22/3, 2019 at 4:22 Comment(0)
M
3

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
Miniver answered 24/5, 2019 at 10:57 Comment(0)
D
1

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.

Dracaena answered 5/3, 2015 at 21:50 Comment(0)
T
1

I had this error when running Update-Migration. Setting the
InvariantGlobalization tag in the .csproj file which you can open up by double clicking on the project to false solved this for me.

Tarrance answered 25/2 at 9:52 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Volution
A
0

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.

Absorbing answered 22/1, 2010 at 11:25 Comment(1)
I did, but didn't foud anything.Jacobian
J
-4

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

Jacobian answered 27/2, 2010 at 14:7 Comment(3)
Wow, that's an old version of VS.NET :-)Wham
That is actually incorrect mate, this is a bug in System.Web, see my reply.Affluent
This is not a VS 2010 bug. It is still a problem in the latest update of 2019Bothersome

© 2022 - 2024 — McMap. All rights reserved.