This morning I made some changes to a project for a future post. Minor stuff and nothing that should have caused issues, but when I tried to run the project I got the following error from Kestrel.
Unable to bind to https://localhost:5001 on the IPv4 loopback interface: ‘An attempt was made to access a socket in a way forbidden by its access permissions.’.
Unable to bind to https://localhost:5001 on the IPv6 loopback interface: ‘An attempt was made to access a socket in a way forbidden by its access permissions.’.
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address https://localhost:5001.
I had limited time so I switched the project over to launch using IIS Express and hit run, but this resulted in the following error.
HTTP Error 500.35 – ANCM Multiple In-Process Applications in same Process
Switching back to Kestrel and changing the port number in the applicationUrl setting in the launchSettings.json file fixed the issue. Later I came back to the application and tried to track down what was using the same ports and couldn’t find anything. After a reboot, all worked fine with Kestrel and the original port numbers.
For the IIS Express error, I ended up having to delete the .vs directory which can be found in the same directory as your solution file if you are using Visual Studio 2019. Thanks to stackoverflow for this fix.
Not the post I set out to write this week, but hopefully this will save someone some searching in the future, more than likely myself.
Also published on Medium.