10

In VS Community 2017 (v15.9.26) I am unable to debug as IIS Express Web Server Produces the following error.

Output for IIS Express: Failed to register URL "localhost:xxxxx/" for site. Error description: Cannot create a file when that file already exists. (0x800700b7)

enter image description here

Steps to try to resolve the issue

  1. Clean, Rebuild, Restart VS, Restart Computer
  2. Deleted the IISExpress folder and re-ran VS SA Source
  3. Deleted the .vs folder and re-ran VS
  4. Created a new virtual directory SA Source
  5. Re-cloned repo in a new directory and started from scratch
  6. Running netsh http show urlacl showed no other process using port
  7. Removed the ComponentModelCache from the VS AppData
  8. Re-installed VS Community 2017
  9. Implemented a confirmed working applicationhost.config with updated references to my paths, still same port issue.
  10. Re-installed IIS 10.0 Express
  11. Turned off anti-virus

I should note that I have three startup projects running. Two of the projects (with different ports) run fine so I can rule out firewall or SSL issues. The third startup application only produces this error.

After trying all 7 steps and resting my computer multiple times I am stuck. Any further solutions/fixes to try would be greatly appreciated!

12
  • What if you stop anti-virus on your machine? Commented Oct 8, 2021 at 20:40
  • @LexLi Since two of my other startup projects run fine I can rule out the firewall, antivirus, SSL issues. Thanks for the ask! Commented Oct 8, 2021 at 21:01
  • 1
    Maybe trial and error testing on port numbers. Commented Dec 14, 2021 at 18:26
  • 1
    stackoverflow.com/questions/5308491/… Commented Dec 17, 2021 at 20:46
  • 1
    Yes they're safe to delete. Standard source control practice say they should never be checked in. Pretty sure they're included in the base .gitignore template and they'll be recreated on the next build. Commented Dec 17, 2021 at 20:48

6 Answers 6

7

I found two temporary workarounds in order to bypass the VS error.

  1. Assign a different port number to the application
  2. Comment out the specific binding protocol in the .vs\config\applicationhost.config

I am still looking for a more sustainable solution.

Sign up to request clarification or add additional context in comments.

1 Comment

Had the same problem. Found the answer - click stackoverflow.com/a/79797642/155077 to jump.
4

I was repeatedly getting this even after changing ports, added new projects, restarted winnat, etc. But ultimately the thing worked for me is;

  1. Close the solution
  2. Delete .vs folder at solution level
  3. Re open the solution and run the app.

2 Comments

Thank you so much! It finally works in VS 2022 after several hours of confusion.
I also had to restart the computer to get it working.
2

These steps solved this issue:

  1. Delete the applicationhost.config in the <project_folder>.vs\config\applicationhost.config
  2. Go to the properties of the project, navigate to the Web Tab, In the Use Local IIS Web Express option. Make sure to give the correct URL and click on Create Virtual Directory
  3. Now Run the application, voila it worked for me!. Hope this works for you as well.

1 Comment

I got "you must specify localhost for the server name" ... really?
1

To resolve that error, perform following steps

  1. Find process who is using the port
  • Open PowerShell as an Administrator
  • Execute command Get-Process -Id (Get-NetTCPConnection -LocalPort <portno>).OwningProcess
  • Look for ProcessName column in output
  1. Kill Process to release the port
  • Open Command prompt as an Administrator
  • Execute command taskkill -f -t -im <processname> where processname is same as retrieved by poweshell command. In my case it was devenv.exe

NOTE: Same process may have other ports in use also. Above command will release all ports

Comments

1

This is the only solution which worked with me. Restarting WinNAT will cause Windows to release ports that it's locking from use.

net stop winnat
net start winnat

Thanks to Matt

1 Comment

This worked for me as well, despite not finding the port being used at all with the netstat | findstr
0

Well, as you found out - a quick but bad workaround is to use a new port.
But I found the solution:

The reason for this is, that you set the HTTPS url in the project's web url setting. WebUrl WebUrlHttps

Resetting the URL won't reset the project.
In addition, as this seems to be saved in the .csproj/.vbproj-file, neither deleting the applicationhost.config file in .vs folder of the project nor deleting the .vs folder in the solution folder nor deleting the applicationhost.config in "%USERPROFILE%\Documents\IISExpress\config\applicationhost.config" will solve this issue.
Neither will resetting URL-reservation with netsh.

The solution is to click on the project (or press F4 when it's on).
There will be a property called "SSL capable/enabled" ("SSL-fähig in German).
ProjectSSlSetting

Set it to false.
Now reset your port in the web section as you originally did. Start it.
It now works with the old port with http (it had registered the old port for ssl, apparently this is inside the .csproj/vbproj file). Now save, and if you turn SSL-capable on again, it will assign a new port for ssl. When you start your project, you can use that URL to start the project on SSL.

SetNewSslUrl Now if that was successful, you can enter the new SSL/TLS-url in the project's web url setting as you originally intended. Visual Studio will now start it up on IIS Express with SSL mode.

ExpressWithSSL

And here you go.
Hope I saved you some headache by posting this.
Have a nice day !

Disclaimer:
If you work with a team, I don't know if this will work for your colleagues.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.