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

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?

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>

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!

I started randomly getting this error. I noticed that the iis express had two sites.
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.

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:
Added the same key twice in the same file (unlikely since you would've seen it)
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>

If you create an IIS website with the physical path the same as the project folder, and then use it create a virtual folder for the project, you are going to see this issue.
Your Web.config file is being loaded twice.
Instead as orjanto pointed out, create an empty folder and point the IIS website to it and then use it to create a virtual folder from Visual Studio.

I had the same problem. It turned out that I had a different project that uses IISExpress with the same port number. Once I changed the project to use a different port number, the error went away.

What worked for me. I deleted the {projectFolderParent}/.vs/config (you have to "show hidden folders/files)
After deleting that, I restarted my computer.

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!

You may find that after upgrading to the latest windows 10 service pack June 2017, this issue is because certain nodes seem to now appear under the root config (machine.config). I removed my duplicates from web.config and it all worked again.

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!

The answer that #orjanto posted solved the problem for me, but I had an additional problem on top of that. After fixing, Internet Explorer still thought that my HTML page was a directory instead of a file.
I had duplicates in my IIS Express config file:
<site name="MyAPI" id="56">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\source\repos\MyAPI" />
</application>
<application path="/login.html" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\source\repos\MyAPI" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:57018:localhost" />
<binding protocol="https" bindingInformation="*:44302:localhost" />
</bindings>
</site>
Note the path="/login.html" in the second <application> entry.
My page was redirecting to "localhost:57018/login.html/" like it was a directory.
Removing the second entry fixed the problem with the configuration file duplicates, however I continued to have a problem where Internet Explorer seemed to think that /login.html/ was a directory (Internet Explorer 11). To diagnose the problem, I checked Chrome and Chrome worked fine.
I went into Internet Explorer, went to Tools > Internet Options > General Tab. Then under "Browsing History" section, I deleted History, Cookies and Website Data, & Temp. Internet Files.

I tried all of the above methods and nothing worked for me. I was keep on getting the error something like
Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'QueryStringModule'
At last I changed my server from
IIS Express to Local IIS in the project property build as given below.
and it worked for me.

I had the same problem, here's what I did:
I changed my Server settings from Local IIS to IIS Express:
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.

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

Related

How do I make Application Warm Up Work on Server 2008 R2 - IIS 7.5?

I have searched through dozens of posts (most of them are a few years old). I would like to speed up the first load of our app and have not found the correct configuration combination to do so on Server 2008 R2. I have it working well on Server 2012 R2 - IIS 8.5. But we still have some sites on Server 2008 R2. What I have done for Server 2008 R2 is:
Installed 'Application Initialization 1.0 for IIS 7.5' and rebooted
Edited applicationHost.config under applicationPools to add:
'startMode="AlwaysRunning"'
Edited applicationHost.config under sites to add 'preloadEnabled="true"' to application path
Edited my application's web.config file to add 'applicationInitialization doAppInitAfterRestart="true"' under system.WebServer
This seemingly has no effect. What am I missing? FWIW, I am using ApplicationPoolIdentity and have Anonymous & Forms Authentication Enabled and ASP.NET Impersonation, Basic, & Windows Authentication Disabled. Any hints are greatly appreciated. Thanks.
After point 2 I would do the following:
Go to your Server in IIS, then double-click on ConfigurationEditor, then Choose:
1-system.applicationHost/applicationPools->Click on (Collection)-> Choose your Pool->Check if "autoStart" is "true" and validate that startMode is "AlwaysRunning"(already done on your point 2)->Then Close the window->Click on apply
2-system.applicationHost/sites->Click on (Collection)->Now Click on the site you want and turn serviceAutoStart to "true",if your site is inside "Default Web Site" press (Collection) below->Now choose your site->Turn preloadEnabled to "true" and serviceAutoStartEnabled to "true" as well.-> close all and apply.
To test go to your pool restarted it in IIS and check in your task manager that w3wp.exe is using your CPU.After some seconds w3wp.exe will stop using your CPU.
For those like me looking for an answer years after all documentation seems to have been wiped from the internet, this worked for me.
Download and install Application Initialization Module for IIS 7.5 from one of the following links (requires reboot): Link 1 Link 2 Link 3
Edit C:\Windows\System32\inetsrv\config\applicationHost.config
Find the configuration\system.applicationHost\applicationPools configuration section
Add autoStart="true" to the application pool used by your web app, so this
<add name="MyCoolAppPool" startMode="AlwaysRunning" enable32BitAppOnWin64="true" managedRuntimeVersion="v4.0" />
becomes this:
<add name="MyCoolAppPool" autoStart="true" startMode="AlwaysRunning" enable32BitAppOnWin64="true" managedRuntimeVersion="v4.0" />
Find the configuration\system.applicationHost\sites\site configuration section
Find the application node for your web app
Add preloadEnabled="true" so the node changes from this
<application path="/UrlPathToMyApp" applicationPool="MyCoolAppPool">
<virtualDirectory path="/" physicalPath="C:\Virtual Directories\MyCoolApp" />
</application>
to this
<application path="/UrlPathToMyApp" preloadEnabled="true" applicationPool="MyCoolAppPool">
<virtualDirectory path="/" physicalPath="C:\Virtual Directories\MyCoolApp" />
</application>
Finally, restart IIS.
Rick Strahl explained a hiccup he had to deal with when installing/configuring it: Add AppWarmupModule to <globalModules> like this:
<globalModules>
<add name="AppWarmupModule" image="%SystemRoot%\system32\inetsrv\warmup.dll" />
</globalModules>

This operation requires IIS integrated pipeline mode

After taking the updates from TFS i start getting this error, Some one suggest me to check the applicationhost file in Documents\IISExpress\config, I think its fine because i can see
<site name="EnviznServicesPlatformGlobal" id="15">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\Dot Net\Timothylos\EnviznGlobalWeb\Test\LatestCode\EnviznGlobalWeb\EnviznServicesPlatformGlobal\EnviznServicesPlatformGlobal" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:1937:localhost" />
</bindings>
</site>
Here applicationPool is showing Clr4IntegratedAppPool mode which seems to be correct to me
I want to change the Manage pipeline mode to integrated like this images
but when i click on properties window i can just just see.
My question is how can i change the Managed Pipeline Mode to Integrated in VS2012?
If you are running an asp.net website you may need to R-click your project and select "Use IIS Express".
If it is a web application you'll need to go into your project's properties pages, select the Web tab then select "Use Local IIS Web server" and check "Use IIS Express".
I had an error (about not using integrated pipeline) which was solved in this way.

Google Earth (.kmz) mime type IIS issue

I am experiencing a peculiar issue with IIS and KMZ files. I have added the MIME type to IIS and it works just fine -- however, seemingly randomly the MIME type is removed. This has happened a few times now, and each time all I have to do to fix the issue is just add the MIME type again.
The issue is identified when broken links are reported, and as soon as I add the MIME type back in all is well.
Any thoughts on what is causing it, or methods for finding out what's causing it?
Thanks!
My guess is that someone is overwriting or modifying your web.config file. You can modify the web.config using either the IIS server tools or by publishing the project containing the web.config file. If you are modifying your IIS settings using IIS Manager, then every time someone re-publishes the web application it changes those settings. Make sure the correct settings are saved in your web.config in your root VisualStudio project. So that whenever that project is published it's setting the correct IIS settings.
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".kml" />
<mimeMap fileExtension=".kml" mimeType="application/vnd.google-earth.kml+xml" />
<remove fileExtension=".kmz" />
<mimeMap fileExtension=".kmz" mimeType="application/vnd.google-earth.kmz" />
</staticContent>
</system.webServer>
</configuration>

IIS 7: value does not fall within the expected range

When I tried to start my IIS server on my local machine (which is running on Windows 7), it is giving me an error saying:
value does not fall within the expected range
I have tried number of thing to correct this issue, but no success. then finally I re-installed the IIS server on my machine but issue is still persist.
Does anyone have any idea about this error? And how can I resolve it?
I have found that, this issue was coming due to incorrect virtual directory was created by visual studio in IIS due to which default web site was unable to start.
What I'd done to resolve this, I'd deleted my Default Web Site and created again in IIS. After that I'd created my application's specific virtual directories. This resolve my problem. Still not know why default web site stop working after incorrect virtual directory created by Visual Studio.
Hope this helps for those who are facing this issue.
I had this issue in IIS 8.5, the problem ended up being an incomplete entry for the host name in the bindings. I didn't include .com on the FQDN.
I have this issue with setting specific accounts for the site to run as..
It goes away if you set the password in the applicationHost.config directly. Cannot do it though IIS anymore though..
In: C:\Windows\System32\inetsrv\config
May help.
I was experiencing the same problem. And the problem was with the file pointed out by #aaron-gibson.
applicationHost.config at: C:\Windows\System32\inetsrv\config
(see here: IIS Configuration Reference)
One of the site had incorrect data:
<application path="/e:\MyFolder\MySiteWithProblem\VDir" applicationPool="AppPool152">
<virtualDirectory path="/" physicalPath="e:\MyFolder\MySiteWithProblem\VDir\Vdir" />
The application path in this case had invalid characters. And also, the physicalPath didn't exist.
Fixing this entry fixed the problem.
The answer marked as the solution fixed the problem because it recreated this file from scratch. But in my case I did not lose all my sites.
I changed the file
applicationHost.config
at: C:\Windows\System32\inetsrv\config
And the entries for each site are in the tags:
<configuration>
<system.applicationHost>
<sites>
...
<site name="Default Web Site" id="1" serverAutoStart="true">
<application path="/MyPath" applicationPool="AppPool152">
<virtualDirectory path="/" physicalPath="e:\MyFolder\MySite\Vdir" />
</application>
...
<site>
...
</sites>
</system.applicationHost>
</configuration>
I had this issue with a new IIS 10 deployment. Our network team copied over the applicationhost.config file from the older servers and this caused it. In IIS 10 there are two new settings that encrypt the password for the app pool identity. Since the IIS 7 config file didn't have those encryption settings then IIS threw this error when assigning a new user. I simply copied over the settings from a brand new server build and it started working fine. Add these two settings to the existing ones already there:
<configProtectedData>
<providers>
<add name="IISCngProvider" type="Microsoft.ApplicationHost.CngProtectedConfigurationProvider" description="Uses Win32 Crypto CNG to encrypt and decrypt" keyContainerName="iisCngConfigurationKey" useMachineContainer="true" />
<add name="IISWASOnlyCngProvider" type="Microsoft.ApplicationHost.CngProtectedConfigurationProvider" description="(WAS Only) Uses Win32 Crypto CNG to encrypt and decrypt" keyContainerName="iisCngWasKey" useMachineContainer="true" />
</providers>
</configProtectedData>
Mine turned out to be an issue with the binding. I deleted than used another name in the binding and it worked great.
Good luck!
I've had this issue and the problem was that the binding was wrong, there was a "space" after the url.
Check your bindings for any wrong characters and if there's anything else wrong with it.
I've had this issue with Octopus Deploy.
It turned out the issue was with the binding where it had an extra space at the end of the hostname when setting up the project in Octopus.
You can also see this from the applicationhost.config in C:\Windows\System32\inetsrv\Config
This message can be caused by a malformed application name in the applicationHost.config file in C:\Windows\System32\inetsrv\config.
For example, I had a "\" in an application name which, once removed, eliminated the error.
This problem can be caused by setting the "Host name" to a number. The "Host name" needs to contain at least 1 letter.
I've had this error message before when I was using an automated build and deployment system (TeamCity with Octopus deploy). It turned out that the port number I'd specified for IIS in the Octopus Deploy variables was too high.
From what I could find on this web site the highest port number IIS will accept is 65535.

iis 7 + http custom handler error: could not load file or assembly The system cannot find the file specified

Windows vista 32 bit - C# - .NET 4 - sqlite - IIS 7
I'm building a small project that contains is a custom HTTP handler where an user can request a XML file and the project will generate the file and send it to the user. It should be flexible enough to send something else too like e.g. json.
Everything was going well until I had to deploy the handler. I've created a library (dll) file which contains the logic for serving of the requested information. I've open IIS manager and I've created a virtual directory to the debug bin file (later on i made it an application. it did not make a difference).
I've followed countless examples and tutorials like these ones:
I started with this one: http://support.microsoft.com/kb/308001
http://msdn.microsoft.com/en-us/library/bb515343.aspx
msdn.microsoft.com/en-us/library/46c5ddfy.aspx
But with no luck. As you could have read I'm not using any asp.net website even though I do have a web.config that I've added to the bin folder and it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true" />
<directoryBrowse enabled="false" />
<handlers accessPolicy="Read, Script, Execute">
<add name="LigoManagedHandler" path="*" verb="*" type="Ligo.Service, Ligo" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
</configuration>
When I try to run handler in the browser get the following error:
Could not load file or assembly 'Ligo' or one of its dependencies. The system cannot find the file specified.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Ligo' or one of its dependencies. The system cannot find the file specified.
I have tried so many possible combination in IIS manager to get it working ('httphandlers', 'classic mode' and so on ...) but i'm truly stuck. The information I've found on the internet is not helping much.
What am I doing wrong or missing to make it work?
Something in this rant triggered an idea, an I stumbled on the answer.
The line in all those tutorials that say put type="ClassName, AssemblyName" into the Handlers section in Web.Config are plain WRONG.
All I did was change this to type="AssemblyName.ClassName" and everything started working, in both a Web Site Project and a Web Application Project that I had created.
I'm running IIS 7.5 in integrated mode so YMMV.
Craig
I figure it out. I had to make a asp.net website project and add my dll as reference to this project.
I read this thread that provided this information which is not clear on the internet.
http://forums.asp.net/t/1088861.aspx/1?What+causes+the+quot+Could+not+load+type+quot+problem+
It should state that it is not possible to make the httphandler without a aspnet website project. or am i mistaken? the example on the internet are incorrect! or provide too little information.
I know, this is an old thread. However, I've been looking for an answer for a few days without finding a clear one. So, in case anyone comes across similar scenario.
You can create custom Http Handler as a stand-alone Class Library project and use it in IIS.
On IIS Add new Application with ASP4 Integrated mode. Place your compiled DLL into bin folder (this is what i was missing all along). Seems obvious that it should be there; took some time to figure this out. :)
web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<handlers>
<add verb="*" path="*.ogg" name="test" type="Namespace.Classname"/>
</handlers>
</system.webServer>
</configuration>
Hope this helps.
Cheers.

Resources