IIS express: Cannot add duplicate collection entry

2019-02-02 21:15发布

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?

12条回答
劳资没心,怎么记你
2楼-- · 2019-02-02 21:51

I had a problem of same type. Running my site published on IIS, the same error was shown.

I saw a web.config file in the wwwroot folder (out of application folder). I removed this file and the application ran OK.

Look for a web.config file placed in a wrong folder (above your folder application).

Good luck!

查看更多
姐就是有狂的资本
3楼-- · 2019-02-02 21:53

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>
查看更多
我想做一个坏孩纸
4楼-- · 2019-02-02 21:53

Just Change the port number which is not yet used by another application and it works

查看更多
We Are One
5楼-- · 2019-02-02 21:56

I started randomly getting this error. I noticed that the iis express had two sites. enter image description here

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.

查看更多
乱世女痞
6楼-- · 2019-02-02 21:56

My Project Url in Web tab inside project properties pointed to wrong url and I was not able to change it ("Would you like to create Virtual Directory?" and VS was locked in a loop (Yes -> Unable to create, No -> Operation Canceled) until I manually reverted Url to the (incorrect) state it was before. The solution was to run VS as Admin. I was able to change that url and everything started to work. Hope it helps!

查看更多
Summer. ? 凉城
7楼-- · 2019-02-02 22:02

I had the same problem, here's what I did:

  • I changed my Server settings from Local IIS to IIS Express:

enter image description here

  • If it still doesn't work, I changed the port number to different port number then click the Create Virtual Directory button. Clean the solution then Rebuild.

enter image description here

查看更多
登录 后发表回答