System.IO.IOException: Failed to bind to address http://127.0.0.1:15080: address already in
use. means another process is already listening on the port your ASP.NET Core app wants, very
often an earlier copy of the same app. Find the process ID with netstat -ano, stop it if it
is yours, or start this copy on another port with --urls.
The two inner exceptions, AddressInUseException and SocketException (10048),
carry the Windows wording for the same thing. Kestrel gives up before it serves a single request, so
the app exits straight away.
The error
Using launch settings from C:\...\k1\Properties\launchSettings.json...
fail: Microsoft.Extensions.Hosting.Internal.Host[11]
Hosting failed to start
System.IO.IOException: Failed to bind to address http://127.0.0.1:15080: address already in use.
---> Microsoft.AspNetCore.Connections.AddressInUseException: Only one usage of each socket address (protocol/network address/port) is normally permitted.
---> System.Net.Sockets.SocketException (10048): Only one usage of each socket address (protocol/network address/port) is normally permitted.
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, Boolean disconnectOnFailure, String callerName)
Only the project path was shortened. The stack trace goes on, and the process then ends with the same
exception on standard error, starting Unhandled exception. System.IO.IOException.
Why it happens
A TCP port takes one listener per address. The first dotnet run was still running in the
background on port 15080, the port in launchSettings.json, so when a second copy asked
for the same port, Windows refused the bind and the host stopped. The usual culprits are a forgotten
terminal or debug session still running the app, or an unrelated program that happens to use the
port.
Note the address. launchSettings.json says http://localhost:15080, the error
says 127.0.0.1. For localhost Kestrel opens two listeners, one on the IPv4
loopback and one on the IPv6 loopback, and netstat shows both belonging to the first
copy. The IPv4 bind failed, so that is the address in the message.
netstat -ano | findstr :15080
TCP 127.0.0.1:15080 0.0.0.0:0 LISTENING 26272
TCP [::1]:15080 [::]:0 LISTENING 26272
tasklist /fi "PID eq 26272"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
k1.exe 26272 Console 1 46,912 K
The holder is k1.exe, the project's own executable, not dotnet.exe:
dotnet run starts your app as a child process, and its parent here was
dotnet.exe run --no-build. In Task Manager, look for your project's name. PowerShell gives
the same process ID:
Get-NetTCPConnection -LocalPort 15080 -State Listen | Select-Object LocalAddress, LocalPort, State, OwningProcess
LocalAddress LocalPort State OwningProcess
------------ --------- ----- -------------
::1 15080 Listen 26272
127.0.0.1 15080 Listen 26272
The fix
Stop-Process -Id 26272
The dotnet run that had started it exited as well, netstat showed only a
TIME_WAIT entry for the port, and the same dotnet run then started cleanly:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:15080
Stop only a process you recognise. If the port belongs to something else, move your app instead:
dotnet run --no-build --urls http://localhost:15081
That copy printed Now listening on: http://localhost:15081 while the first one kept port
15080, and both answered Hello World!. To make the move permanent, change
applicationUrl in Properties\launchSettings.json; set to
http://localhost:15082, the next dotnet run listened there.
How it was reproduced
A project from dotnet new web with the template's Program.cs unchanged, and the
http profile's applicationUrl set to http://localhost:15080. One
dotnet run was started in the background, then a second dotnet run in the
same folder; the second failed as shown and exited with code -532462766. .NET SDK 10.0.401,
ASP.NET Core 10.0.12, Windows 11.
Frequently asked
- How do I find which process is using a port on Windows?
- Run netstat -ano | findstr :15080 (with your port) and read the process ID in the last column, then tasklist /fi "PID eq 26272" (with that ID) to get its name. In PowerShell, Get-NetTCPConnection -LocalPort 15080 -State Listen shows the same ID as OwningProcess.
- Why does Kestrel say 127.0.0.1 when I configured localhost?
- For localhost Kestrel binds the IPv4 and IPv6 loopback addresses as two separate listeners. The bind to 127.0.0.1 is the one that failed, so that is the address the exception names.
- How do I run an ASP.NET Core app on a different port?
- For one run, pass --urls, for example dotnet run --urls http://localhost:15081. To change it for every dotnet run, edit applicationUrl in the profile you use in Properties/launchSettings.json.
More decoded errors in the Fixes category. The same forgotten copy of your app also locks its own build output; that one is covered in dotnet build fails because the DLL is locked.