Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS express: Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to

In Visual studio, Solution->Web.Project->Properties->Web, I have changed my Project Url from http://localhost:51123/ to http://localhost:51123/NewProjectName and I keep getting this error:

"Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to ...." on every module added.

Adding a remove tag works but then it should have been a problem even before i changed the url. Any suggestions?

like image 963
Prasath Siva Avatar asked Aug 29 '13 09:08

Prasath Siva


4 Answers

I think IIS Express probably has 2 <application>-blocks and both will be pointing to the same physicalPath.

Go to the IIS Express config file in: My Documents\IISExpress\config\applicationhost.config

Search for NewProjectName

Change the physicalPath for the root application to something else. Point it to an empty folder.

Should look something like this:

<site name="NewProjectName" id="1">
  <application path="/" applicationPool="Clr4IntegratedAppPool">
    <virtualDirectory path="/" physicalPath="c:\Temp" />
  </application>
  <application path="/NewProjectName" applicationPool="Clr4IntegratedAppPool">
    <virtualDirectory path="/" physicalPath="c:\sourcecode\NewProjectName" />
  </application>
  <bindings>
    <binding protocol="http" bindingInformation="*:51123:localhost" />
  </bindings>
</site>
like image 112
orjanto Avatar answered Nov 03 '22 05:11

orjanto


Also, ensure you don't have a duplicate web.config file in one of the parent folders (eg: a web.config backup file). That was the issue with mine!

like image 45
Shirlz Avatar answered Nov 03 '22 07:11

Shirlz


I started randomly getting this error. I noticed that the iis express had two sites.

Screenshot of two websites running in IIS express

This double layer is causing IIS to read the web.config from the first site and second at \WFM, therefore finding duplicates. I just stopped all the sites and removed the \WFM from my web project path. However you could go clear the files and folders from your temp file in IIS express. In my case I had multiple versions of the solution and one solution's project\user config had an extra path in the web project URL. VS 2015 added it, or someone checked in their own user config to TFS. Hope this helps others.

like image 17
Steve Coleman Avatar answered Nov 03 '22 05:11

Steve Coleman


All web.config files work off multiple cascading levels of inheritance at the machine, IIS, project, and folder level locations, with each providing a higher degree of specificity.

If you're getting this error, it means you've either:

  1. Added the same key twice in the same file (unlikely since you would've seen it)
  2. The same key already exists in a separate file higher up the inheritance chain

There can be a lot of different root causes for #2, but if you want to side step them, you can just remove any previous declarations and then re-add your own at that level (I'd pay good money for an upsert feature).

So just add <remove> tags like this for any offending elements:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">

    <remove name="ErrorLog" />
    <remove name="ErrorMail" />
    <remove name="ErrorFilter" />

    <add name="ErrorLog"    type="Elmah.ErrorLogModule, Elmah"    preCondition="managedHandler" />
    <add name="ErrorMail"   type="Elmah.ErrorMailModule, Elmah"   preCondition="managedHandler" />
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />

  </modules>
</system.webServer>
like image 14
KyleMit Avatar answered Nov 03 '22 06:11

KyleMit