0

My .Net Web API program keeps showing me the same error whenever I try to debug it. Here is the error:

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:5082: address already in use

I'm programming on Macbook M1 and VS Code btw.

It didn't help changing the port number.

I run it by typing "dotnet run" on terminal, after it started running I select the .NET Core Launch(web) configuration and click the run button on VS Code Run and Debug component. If I click this button without starting the program or just click Run->Start Debugging, it can't find the localhost on that port number. However, running the program on Swagger with "dotnet watch run" does not cause any problem, it works perfectly.

I've checked if that port number really in use by typing "lsof -i 5082" before running the program but nothing showed up. I feel like "dotnet run"+"Run and Debug button" combination tries to run the program 2 times but I couldn't find the proper way to do it.

Kerem
  • 11
  • 3
  • You need to make sure you're running `lsof` with sufficient privileges too (as `lsof` will hide processes you don't have permission to see, even if they are using that port number) – Dai May 08 '23 at 09:38
  • @Dai It doesn't give any "port is already in use"errors when I try to run it with "dotnet watch run" – Kerem May 08 '23 at 09:42
  • When you say "terminal window" - do you mean the macOS Terminal/zsh app, or the Terminal panel/window within VS Code? – Dai May 08 '23 at 09:49
  • @Dai I'm using MacOS terminal to use "lsof" command, VS Code terminal for other things I've mentioned. – Kerem May 08 '23 at 09:57
  • What happens if you run `lsof` within VSCode? And exactly what build/version of macOS are you running? – Dai May 08 '23 at 09:58

0 Answers0