IIS7 Error: cannot add duplicate collection entry of type ‘mimeMap’ with unique key attribute ‘fileExtension’ . . .
Problem:
For the sake of comparison, in IIS6 (Windows 2003) if you add a mime type (example: .xyz - xml/text) at the virtual directory level and then also attempt to adds the same mime type at the web site level, IIS6 will alert you that a child entity has an override for the mime type. If I accept the override, all entities under the web site will inherit the mime type, but the one with an explicit value will override the inherited one.
By contrast, in IIS7 (Windows 2008 and Vista), adding the same mime types at the application level (which IIS will place into a web.config file) and the site level (which IIS will place into the applicationHost.config file) may cause a conflict. No warning is given except for an error in the client browser that goes something like this:
Server Error in Application
Internet Information Services 7.0
HTTP Error 500.19 - Internal Server ErrorMIME Types
There was an error while performing this operation.
Details
Filename
\\?\c:\something\something\.....\web.config
Line number: 25
Error: cannot add duplicate collection entry of type ‘mimeMap’ with unique key attribute ‘fileExtension’ set to ‘.xyz’
OK
Solution:
One solution would be to simply remove one of the two conflicting mimeMap extensions from one of the config files. However, in some rare scenarios the IIS administator may need to not remove one of the two conflicting mime mappings. If both mimeMaps are needed, the way to get around the conflict is to make one simple addition to the web.config which will do a REMOVE immediately prior to doing an ADD.
So if your application installation adds the following line to the web.config. . .
<mimeMap fileExtension=".xyz" mimeType="xml/text" />
… And this line creates a conflict with the same mime map in the applicationhost.config file, all you have to do is add the following line ABOVE that line so that it will look like the following:
<remove fileExtension=".xyz" />
<mimeMap fileExtension=".xyz" mimeType="xml/text" />
Doing the remove before the add should be fine even when the .xyz mime map doesn't exist at a higher level.
Comments
- Anonymous
March 22, 2012
I believe this is the type of error only affects the developer and system administrators. It's so simple to solve in the IIS kernel that it is a shame the option was to throw an exception.The developer that did that could have override the dictionary with the local choice of mimeMap - the obvious, expected way for configuration files to work!And then lots of people working and writing books and tools for: defensive web.config practices, code editors with macros and templates, fxcop rules for detecting "code smells" in config files, Best Practice Analyzers, etc... - Anonymous
November 14, 2012
How do i fix this, when trying to add the mimetype with PowerShell? - Anonymous
July 23, 2013
He simple engineer, its not about how easy the task looks to be to you but it simply everything single action, error, solution, has to be well documented - Anonymous
May 08, 2014
Thanks! That was exactly my problem!I had mapped .jsp already in an isapi config file and then mapped .jsp in MINE-Type again in Home directory for IIS which led to the same error.Deleting the MIME-Type mapping solved my isue! - Anonymous
May 08, 2014
Glad it helped, Han! - Anonymous
November 17, 2014
Thanks for this! Helped me to solve the problem :) - Anonymous
December 08, 2014
Had a problem with .svg so I added <remove fileExtension=".svg" /> and it worked. Thanks! - Anonymous
March 02, 2015
Thanks, it resolved my issue straightaway. - Anonymous
March 11, 2015
<remove fileExtension=".xyz" />it solve my problem...Thanks - Anonymous
February 04, 2016
I am getting below error while launching Error Pages in IIS. Cannot add duplicate collection entry of type 'error' with combined key attributes 'statusCode, subStatusCode' respectively to set '401, 1'. Same error I am getting when I am lauching my website. Please help.