Unable to add duplicate record for collection of type 'add' with unique key attribute 'name' set to 'aspNetCore

I recently published an ASP.NET Core application for my host. I find HTTP Error 500.19.

IIS 8.5 says the problem is this: -

"Unable to add a duplicate collection entry of type 'add' with the unique key attribute 'name' set to 'aspNetCore'

It also emphasizes this key add line in my system.webServer configuration: -

<handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" </handlers> 

I'm not sure what to do with this. It seems like there is a duplicate of the instance, so I tried renaming it, but it still wants to add it again?

Here is my web.config: -

 <?xml version="1.0" encoding="utf-8"?> <configuration> <!-- Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380 --> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/> </system.webServer> <system.net> <defaultProxy useDefaultCredentials="true" > </defaultProxy> </system.net> </configuration> 
+21
source share
8 answers

The answer above did not help me, however DavidG's comment solved my problem, so I am sending the message as an answer if it helps someone else.

For me, I did not run it as a sub-application, and a project that worked for me without any problems for a year suddenly stopped working with this problem. Still not sure what has changed. When I commented or deleted <add name="aspNetCore".../> , the error continued, and then this line was automatically added.

To solve this problem, I added <remove name="aspNetCore" /> to the configuration file right above the <add name="aspNetCore"... /> , and it worked again.

+15
source

To continue working in IIS EXPRESS, go to the root folder where the .sln file is located.

go to delete the file from .vs \ config \ applicationhost.config or save it in a temporary place if you have something there.

Close / Re Open VS Studio, run again, will work.

If you need to add something back from save applicationhost.config, just compare the two, but I donโ€™t see what you could have there.

+7
source

Unfortunately, none of the proposed solutions helped me. By some miracle, I found out that my applicationhost.config file was modified, unfortunately, due to which I got the error "Unable to add duplicate collection" when going to a specific page in my .NET Core web application.

Under the <sites> in applicationhost.config , I had the following:

 <site name="MyWebsite" id="2"> <application path="/" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="C:\Users\___\solutionname\MyWebsite" /> </application> <application path="/SomePage" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="C:\Users\___\solutionname\MyWebsite" /> </application> <bindings> <binding protocol="https" bindingInformation="*:12345:localhost" /> </bindings> </site> 

The HTTP error 500.19 seemed to me when I went to the "/ SomePage" page. As you can see, for some reason there was a separate <application> tag for this particular page. I have no idea why.

I removed all this <application> for the path / SomePage and it worked again.

+6
source

I had the same problem and in my case commented out the line

 <add name="aspNetCore"... 

solved the problem and raised the question "why does it work without AspNetCoreModule". In my case, the problem was that I was adding the site as a sub-application to defaultwebsite and it was located in wwwrootfolder. I think the configuration was automatically loaded by default and was applied to all sub-application sites.

This link has helped

Thus, the solution was to move it as a separate site to another port.

+3
source

I ran into this problem compared to 2017 in a project that worked fine without changing web.config. Looking through these posts, I realized that this could be an IIS Express problem, and decided to simply delete the .vs folder and restart it.

+3
source

In my case, the problem was caused by putting the path in the Debug tab of my web project so that the application opens on a specific page. This results in two silent additions to the .vs \ config \ applicationhost.config file, similar to the one seen in eights.

IN:

 <add name="api AppPool" managedRuntimeVersion="" /> 

IN:

 <application path="/blah" applicationPool="api AppPool"> <virtualDirectory path="/" physicalPath="your-path\src\your-proj" /> </application> 

where a similar entry already exists. This is the root of the problem.

Unfortunately, the error message is misleading.

The solution is to rename applicationhost.config, restart VS and let it rebuild the file. That's why Ricardoโ€™s decision to delete the entire .vs folder also works.

0
source

This error is due to the fact that ASP.NET Core has a root file named ".vs \ config \ applicationhost.config". Initially, it has 67 keys. You can see it here in the Configuration Editor. Where to find the ApplicationHost.config

This file, named ".vs \ config \ applicationhost.config", has the default settings that Web.config brings to work, and one of them is this handler. You can also see it here. Key aspNetcore

The problem is that this file has this handler, and what you publish will inherit this handler.

You have two solutions: comment on the line of your published web.config or remove this handler from ".vs \ config \ applicationhost.config"

0
source

I just had this one, it turned out that I changed the application URL in the debug settings for website properties to load a specific page (wrong, but it happened).

enter image description here

In IIS, he automatically created a new application in a test domain called About (in this case).

Removing a fraudulent IIS application from the domain solves the problem because it does not try to reload the same web.config file when it goes to the page.

0
source

All Articles