Reputation: 3162
I am just starting working with ASP.NET Core 2.0 on a Windows machine. I cannot run kestrel server due to the port 5000 being used by some other apps.
Exception has occurred: CLR/System.IO.IOException An unhandled exception of type 'System.IO.IOException' occurred in System.Private.CoreLib.dll: 'Failed to bind to address http://127.0.0.1:5000: address already in use.'
The issue is that I kill the process and run the dotnet run
command. It works but for the second time I get the error again. So somehow I should the port should be released when I stop debugging but it doesn't. Any tips?
Upvotes: 3
Views: 15922
Reputation: 9869
Try these commands in an admin command prompt:
net stop winnat
net start winnat
It will restart the service "network address Translation". The service reserves ports dynamically and once in a while it will reserve ports that collide with your application. The commands solve the problem for me most of the times, no need to change port.
Sources:
How to see what is reserving ephemeral port ranges on Windows? https://github.com/dotnet/core/issues/2001
Upvotes: 1
Reputation: 9
I had the same problem, and based on the karnveer0098 answer, I just changed the line "applicationUrl": "http://localhost:60758" inside of 'launchSettings.json', to another port number, then all came back to normal.
Upvotes: 0
Reputation: 9
I have faced the same. Here is the solution please refer to this:-
https://github.com/dotnet/core/issues/3110
change your port in the program.cs and launch setting.json file.
eg - : webBuilder.UseUrls("http://localhost:6980");
Upvotes: 0