"Unable to launch the IIS Express Web server." in Visual Studio

I attempted to run my web service through visual studio. I faced an issue like :

---------------------------
Microsoft Visual Studio
---------------------------
Unable to launch the IIS Express Web server.

Failed to register URL "http://localhost:63591/" for site "xxxxxx" application
"/". Error description: The process cannot access the file because it is being
used by another process. (0x80070020)

---------------------------
OK   
---------------------------

I saw the task manager and found that PID 4 is used by System and its Description is NT Kernel & System. So I tried to stop the http service. All dependency services stopped. But I am facing an issue in stopping http service like

The service is starting or stopping.  Please try again later.

So, I tried to stop and start the service manually. But the End process is disabled. It will be helpful if anyone could help with this issue


Solution 1:

I had a similar issue when trying to run a project from Visual Studio 2019 on Windows 10. The application could not start because the port was apparently being used by another process. However, the netstat command showed that the port was not being used by any application.

After spending 2-days Googling I found a solution that worked for me. The port I was trying to use was in the excluded port range which you can see by running the command:

netsh interface ipv4 show excludedportrange protocol=tcp

The culprits that reserved these ports in my case were Docker for Windows and Hyper-V

The Solution

I uninstalled Docker (as I did not need it) and disabled Hyper-V. To disable Hyper-V: Go to: Control Panel-> Programs and Features-> Turn Windows features on or off. Untick Hyper-V and restart the computer.

After the restart the command netsh interface ipv4 show excludedportrange protocol=tcp showed no ports reserved.

I then added the port for my application to the excluded port range by running the following command from an elevated command line:

netsh int ipv4 add excludedportrange protocol=tcp startport=50403 numberofports=1 store=persistent

Then I reenabled Hyper-V (Docker can be reinstalled if needed) and restarted the computer again.

Hyper-V now reserved its ports without interfering with the port used by my application: Reserved Port Ranges

Solution 2:

From https://www.davidsalter.co.uk/unable-to-launch-the-iis-express-web-server-error-0x80070020/

Error code 0x80070020 means ERROR_SHARING_VIOLATION, which in the case of IIS Express (or IIS) means that the port that it is attempting to listen on is being used by another process.

Use the netstat command to find out which application is using the port.

netstat -ao | findstr <port_number_to_search_for>

The a parameter tells netstat to display all connections and listening ports.

The o parameter tells netstat to display the process ID associated with the connection.

Running the above netstat command will produce output such as:

C:\>netstat -ao | findstr 4026
TCP    12.0.0.1:4026        cs-pc:4026         LISTENING       9544

The last number displayed (9544 here) is the process ID.

Solution 3:

Solution that worked from me is,

To fix this you must temporarily disable the winnat service, this is simply done by running this command (must be run as administrator)

net stop winnat

Start your docker services and start winnat again

net start winnat

Solution posted at http://www.herlitz.nu/2020/12/01/docker-error-ports-are-not-available-on-windows-10/

Solution 4:

I had the same problem. I just restarted Visual Studio and it worked.

Solution 5:

I had the same Issue. As @Kautsky Lozano mentions above Another application is using that port.

So [for a Windows OS] just:

  • Open Resource Monitor (Task Manager -> Performance -> Open Resource Monitor )
  • Click on the Network tab.
  • And at TCP Connections find the application that uses the Local Port that IIS Express uses and close it. (it was firefox on my case)