IIS7 Error: cannot add duplicate collection entry of type ‘mimeMap’ with unique key attribute ‘fileExtension’ . . .


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 Error

MIME Types
There was an error while performing this operation.
Line number: 25
Error: cannot add duplicate collection entry of type ‘mimeMap’ with unique key attribute ‘fileExtension’ set to ‘.xyz’



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

  1. The solution is simple, but the engineer could have done better says:

    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…

  2. Anders says:

    How do i fix this, when trying to add the mimetype with PowerShell?

  3. Patrick says:

    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

  4. Han says:

    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!

  5. Ch3rub says:

    Thanks for this! Helped me to solve the problem 🙂

  6. Alex Kamburov says:

    Had a problem with .svg so I added <remove fileExtension=".svg" /> and it worked. Thanks!

  7. Naz says:

    Thanks, it resolved my issue straightaway.

  8. Asad says:

      <remove fileExtension=".xyz" />

    it solve my problem…


  9. Nitin K says:

    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.