9

I have a asp.net core (.net5) project that when I launch it systematically throws errors after a delay, and then closes the debug.

I have the following launchSettings:

{
  "iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": false,
    "iisExpress": {
      "applicationUrl": "http://localhost:50868",
      "sslPort": 44363
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Kestrel": {
      "commandName": "Project",
      "dotnetRunMessages": "true",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

I launch the project in debug mode as "Kestrel"

One or more errors occurred.

Failed to launch debug adapter. Additional information may be available in the output window.

Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:55743).

enter image description here

It seems it does try to connect to a random port like 127.0.0.1:55743 when the project is set to launch the browser at https://localhost:5001 or 5000 enter image description here

Seems related to this issue https://github.com/dotnet/aspnetcore/issues/28113

PS. The debug is working fine with Edge (I usually work in Chrome), I suppose there is need to change the browser if you have such issue....

serge
  • 13,940
  • 35
  • 121
  • 205
  • 1
    Where do you see `127.0.0.1:55743`? In the screenshot is `127.0.0.1:56174`. Does the port change on each try? – vernou Mar 03 '21 at 12:22
  • @Vernou yes, it changes every time – serge Mar 03 '21 at 13:07
  • it seems the configured ports are busy, don't know why it launches them twice... updated the OP – serge Mar 03 '21 at 21:30
  • 1
    Check [this thread](https://stackoverflow.com/questions/50292932/cannot-debug-in-visual-studio-2017), try to clean the project, then Disabled JavaScript debugging for Asp.Net in Visual Studio 2019. Or, refer [this thread](https://stackoverflow.com/questions/65230472/one-or-more-errors-occurred-failed-to-launch-debug-adapter-visual-studio-2019), go to Visual Studio 2019 Tools and then click on Options, select Debugging and then enable the option Automatically close the console when debugging stops. – Zhi Lv Mar 04 '21 at 06:56
  • 1
    I observed that changing the default browser helps... But is rather a workaround, not a solution – serge Mar 04 '21 at 10:51
  • disabling JavaScript debugging worked for me – Qwerty Jun 22 '22 at 06:04

3 Answers3

23

I tried several solutions, not sure what one really helped, but you can try one the following:

  • Disable/Enable JavaScript Debugging in VS options: enter image description here

  • Change the default launch browser to see if it helps (say, launch in Edge or Firefox instead of Chrome)

  • uncheck the "launchbrowser" in the project debug settings, launch the debug and then open manually your startup link (localhost or other you configured to launch)

  • open your resources monitor and check if the port you try to open is not already taken by another process (open TaskManager, go to Performance tab and in the bottom ov the window you have the resources monitor. Alternatively launch the "resmon.exe" from command line. Then go to network tab and the last "Ports".

serge
  • 13,940
  • 35
  • 121
  • 205
  • 7
    The answer to this is what @serge mentioned. However, if you do have "Enable JavaScript.." checked and you still have this problem... ensure that the browser from the previous debug session is completely closed. That worked for me. – Jason Washo Feb 10 '22 at 14:51
  • To me this error occurred because the Swagger UI window of a previous session was not closed. Normally VS closes this window when the debugger is stopped. Closing this window manually solved it. – Patrick Koorevaar Mar 18 '22 at 18:08
  • I changed default browser and it did work for me. – Garry Nov 29 '22 at 19:54
  • @Garry probabily changing the browser worked like you would close all other browser's sessions. – serge Aug 01 '23 at 11:40
2

Taken from Jason's comment, I had a browser left open from a previous debug session. I closed it and this error went away.

Rudy Scoggins
  • 431
  • 3
  • 8
0

I disabled script debugging on a ASP.net WebForms project that I'm working on, and was able to finally get around this error.

In my case, it was intermittent but resolved by clicking arrow next to the web browser selection and go to "Script Debugging". Mine was previously enabled, and setting it to disabled fixed the issue.

AlphaG33k
  • 1,588
  • 1
  • 12
  • 24