I had a similar issue running Visual Studio 2019 on Windows 10.
Some solutions that worked for others seemed to include:
- Changing the application port number.
- Have Visual studio automatically assign a port number each time the application start.
- Restart Visual Studio
- 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:
- Disable Hyper-V: Control Panel-> Programs and Features-> Turn Windows features on or off. Untick Hyper-V
- Restart the computer.
- Add the port you are using to the port exclusion range:
netsh int ipv4 add excludedportrange protocol=tcp startport=50403 numberofports=1 store=persistent
- Reenable Hyper-V
- Restart the computer
From here everything worked perfectly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…