开发者

The type initializer for 'System.Web.MimeMapping' threw an exception: Item has already been added. Key in dictionary: '.fif' Key being added: '.gif'

开发者 https://www.devze.com 2023-02-24 06:23 出处:网络
I\'ve never seen anything like this before. Tried everything I could, searched the web with no luck and in the end I have absolutely no idea what\'s going on. I bet this is going to be one of those si

I've never seen anything like this before. Tried everything I could, searched the web with no luck and in the end I have absolutely no idea what's going on. I bet this is going to be one of those silly easy to fix bugs, although I don't quite get the fif/gif key issue -- too surreal for me.

More info: currently running MVC3 (upgraded from 1 to 2 to 3), issue is intermittent (sometimes happens on site load, sometimes it takes a few or several minutes to happen), running site directly on Visual Studio.

Any help is greatly appreciated!


Server Error in '/' Application.

Item has already been added. Key in dictionary: '.fif'  Key being added: '.gif'

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information a开发者_StackOverflow社区bout the error and where it originated in the code. 

Exception Details: System.ArgumentException: Item has already been added. Key in dictionary: '.fif'  Key being added: '.gif'

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[ArgumentException: Item has already been added. Key in dictionary: '.fif'  Key being added: '.gif']
   System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) +9360827
   System.Collections.Hashtable.Add(Object key, Object value) +11
   System.Web.MimeMapping..cctor() +2038

[TypeInitializationException: The type initializer for 'System.Web.MimeMapping' threw an exception.]
   System.Web.MimeMapping.GetMimeMapping(String FileName) +23
   System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath) +761
   System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) +347
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862964
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.431


In my case this error was caused by wrong web.config configuration. I had

<staticContent>
  <mimeMap fileExtension=".ttf" mimeType="font/otf" />
</staticContent>

but it should be

<staticContent>
  <remove fileExtension=".ttf" />
  <mimeMap fileExtension=".ttf" mimeType="font/otf" />
</staticContent>


So here's the deal:

Apparently, there's an issue with the "cy-GB" culture comparer, which in turn caused the odd fif/gif issue.

More info here: http://forums.iis.net/p/1175210/1979005.aspx and https://connect.microsoft.com/VisualStudio/feedback/details/661862/system-web-mimemapping-static-constructor-crash-due-to-incorrect-string-comparer-use

What caught my attention was that that culture was being picked from the application, and the reason is because of a FirstOrDefault() where two letter ISO code == "GB". Now that's been resolved, and the issue no longer happens, but the "cy-GB" culture bug is still to be fixed (MS Connect link provided above).

Hope this helps anyone else with a similar issue.


I just had this exact same problem. Thanks for pointing to the cause, Eddie.

This is what I did to fix this problem on my Windows XP machine:

Go to Control Panel > Regional and Language Options > Regional Options (tab) > Standards and formats. Then select English (United Kingdom) from the drop-down menu, rather than Welsh.

0

精彩评论

暂无评论...
验证码 换一张
取 消