What to Do if Visual Studio Cannot Run Your ASP.Net Application Outside of the Debugger

After a long time, I am back at an annoying problem with Visual Studio. One ASP.Net application works when I start it through “With Debugging“, but it fails when I try “Run Without Debugging“:

The option with debugging works, the one without does not.

The error I get is this one:

Unable to launch the IIS Express Web server.

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

The reason for this error is that in the file .vs\PROJECT\config\applicationhost.config is an HTTP binding for port 2009 that is used by some other process:

As soon as I delete the HTTP binding, Visual Studio runs the site without a problem outside of the debugger. That is until a few runs later when it recreates this entry and IIS can no longer start.

This behaviour only affects one application, while the rest works as expected. In the past I stopped at digging deeper and keep deleting the binding whenever it happened. That worked as long as it where hours between the problems, but now I had to fix it every 15 minutes. This time I wanted to fix this problem for good.

Inside the *.csproj files you can find the settings for the development server. In the DevelopmentServerPort property I can find the value 2009 which is the one from the HTTP binding:

I changed the value for DevelopmentServerPort, reloaded the project and restarted Visual Studio. Visual Studio rewrote the binding, but it used a different port. So, I took this port and repeated the steps to change it in the *.csproj file. Since I changed the port Visual Studio no longer has a problem to start the web application without the debugger. I hope it stays that way.

I am not really happy with the solution. It works, but only until someone else in the team needs to change the port because it collides with a process on their system. Please post a comment if you know a better solution.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.