Failed to bind to address https://127.0.0.1:5001: address already in use
Trying to run a freshly created project I get the following. Seems like a race condition because port 5001 is not in use on my system.
[41m[1m[37mcrit[39m[22m[49m: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address https://127.0.0.1:5001: address already in use. ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use ---> System.Net.Sockets.SocketException: Address already in use
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransport.BindAsync()
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransport.BindAsync()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass22_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.LocalhostListenOptions.BindAsync(AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
Microsoft.AspNetCore.Server.Kestrel:Critical: Unable to start Kestrel.
System.IO.IOException: Failed to bind to address https://127.0.0.1:5001: address already in use. ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use ---> System.Net.Sockets.SocketException: Address already in use
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransport.BindAsync()
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransport.BindAsync()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass22_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.LocalhostListenOptions.BindAsync(AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
The thread 1215731 has exited with code 0 (0x0).
The thread 1215727 has exited with code 0 (0x0).
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
There is already this issue logged. Did you check the solution of checking Port Usage (by some other application) and killing it?
https://github.com/dotnet/core/issues/948
Are you on HTTPS on localhost?
Duplicate of #948
Okay, but what is the solution?
@jenyckee did you check the primary issue?
@karelz Yes, when I "Start Without Debugging" the application even crashes
This also happens to me
I had the same issue on a dotnet generate web project recently. But I can fix the issue by editing Properties\launchSettings.json to modify the applicationUrl in your app config.
From this
"applicationUrl": "https://localhost:5001;http://localhost:5000",
to this
"applicationUrl": "http://localhost:5000",
I suspect it could be an issue of the dotnet boilerplate project "ASP.NET Core Web API".
@reevelau This doesn't help for me
@jenyckee did you check the primary issue? ... Yes, when I "Start Without Debugging" the application even crashes
See https://github.com/dotnet/core/issues/948#issuecomment-336284252 ... unless the right team knows about the problem and understands the root-cause, they can't provide solutions.
@karelz That's very unfortunate, what kind of information do you need in order to understand the root-cause?
@jenyckee please read the link https://github.com/dotnet/core/issues/948#issuecomment-336284252 - it tells you where to file the bug (aka where to find the right team to talk to). No information you provide here or on the #948 bug is going to help as it won't reach the expert.
I had the same issue on a dotnet generate web project recently. But I can fix the issue by editing
Properties\launchSettings.jsonto modify theapplicationUrlin your app config.From this
"applicationUrl": "https://localhost:5001;http://localhost:5000",to this
"applicationUrl": "http://localhost:5000",I suspect it could be an issue of the dotnet boilerplate project "ASP.NET Core Web API".
Still can't
{ "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:5001", "sslPort": 5001 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "johnTestBO": { "commandName": "Project", "launchBrowser": true, "launchUrl": "api/values", "applicationUrl": "https://localhost:5001", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }
In my case the reason was that I had a web site on IIS bound to use https://localhost:5001
Funny enough "netstat -o" didn't show it
on CentOS 7 ,I had the same issue on a dotnet generate web project recently.

{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:56271/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"CategoryProjectCore": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
},
"ConnectionStrings": {
"SopContext": "server=127.0.0.1;port=3306;database=sopcce;uid=root;pwd=123456;Charset=utf8mb4;SslMode = none;"
}
}
I do not know ,try other way #948 not help me.
@Sopcce please do not comment on close issues. We rarely monitor them. I would suggest to file a new issue with details - it would be good to summarize what EXACTLY you tried that did not help you. The issues are now too long and too messy to make heads and tails clearly. Thanks!
If people are still commenting on a closed issue, it's probably because it's what they are most directed to which likely means the issue shouldn't be closed in the first place. We have 948 (closed), this ticket (closed). I'm not sure opening yet another one makes sense.
For those who want another experience report: this exact same issue currently happens to me all the time as well, with a fresh install of dotnet. The project is here:
https://github.com/jeffnyman/testing-aspnet-core
Running dotnet run works just fine with this project on Windows, not at all on Mac (either Sierra, High Sierra or Mojave).
It initially tells me port 5000 is in use. It's not; I've checked. But I did run the kill steps on anything on the port as provided by seba-i. I then added the following line to Startup.cs:
.UseUrls("http://*:5001")
When I do that, then it tells me port 5001 is already in use. I realize the issue is closed but a lot of people are going to probably end up here as they experiment.
fix the issue by editing
Properties\launchSettings.jsonto modify theapplicationUrlin your app config.From this
"applicationUrl": "https://localhost:5001;http://localhost:5000",to this
"applicationUrl": "http://localhost:5000",I suspect it could be an issue of the dotnet boilerplate project "ASP.NET Core Web API".
I just tried to create a new project on .net core 2.2 and had the same issue. dotnet new mvc --auth Individual -o AspNetCoreTodo dotnet run
making this change worked for me.
If you use Visual Studio Code you need to close application in terminal. Maybe you run your application using dotnet run command. Then it started. Even you close your tab in browser it still works. You need to go to terminal tab in your Visual Studio Code and then press "ctrl + c" to stop the application. After that you should have problem with starting it using debug or withoud debug command.
I solved it here by deleting the "applicationUrl" in launchSettings.json

I created a new project in VSCode with dotnet new mvc command Then run the app through terminal using dotnet run. It just froze after a few info statements. I ran using the debugger. Gave me the error - Failed to bind to address https://127.0.0.1:5001: address already in use.
Here's what I did - Stopped the debugger. Hit Ctrl+C on terminal. Reran using the Debugger. Worked fine for me.