Why and how to fix? IIS Express “The specified port is in use”

I had a similar issue running Visual Studio 2019 on Windows 10.
Some solutions that worked for others seemed to include:

  1. Changing the application port number.
  2. Have Visual studio automatically assign a port number each time the application start.
  3. Restart Visual Studio
  4. Restart the computer.

Unfortunately, none of these solutions worked for me, assigning another port number did work but was not an acceptable solution as it was important for my application to run on a specified port.

The Solution

First I ran the command:

netsh http add iplisten ipaddress=::

from an elevated command-line process. This solved the initial error, when attempting to run the application I no longer got the “port in use” error, instead, I now got an error stating the application was unable to bind to the port because administrative privileges were required. (although I was running Visual Studio as administrator)

The second error was caused by Hyper-V that adds ports to the Port Exclusion Range, the port my application uses was in one of these exclusion ranges.
You can view these ports by running the following command: netsh interface ipv4 show excludedportrange protocol=tcp

To solve this second error:

  1. Disable Hyper-V: Control Panel-> Programs and Features-> Turn Windows features on or off. Untick Hyper-V
  2. Restart the computer.
  3. Add the port you are using to the port exclusion range: netsh int ipv4 add excludedportrange protocol=tcp startport=50403 numberofports=1 store=persistent
  4. Reenable Hyper-V
  5. Restart the computer

From here everything worked perfectly.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)