Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2019 ,NET Core 5.0 Razor Pages ~ Unable to launch browser could not connect to debug target

I have two .NET Core 5.0 Razor Page Model projects, almost identical, reside in the same solution. Have not been running for almost 4 months.

Now when I wish to make some changes. One of the project cannot run in debug mode. I am always getting the following error

Error when launch with debug

{"tag":"dap.receive","timestamp":1625537078095,"metadata":{"connectionId":0,"message":{"type":"request","command":"launch","arguments":{"WebRoot":"xxxx\ApmtWeb\wwwroot","rootPath":"xxxx\ApmtWeb\wwwroot","__workspaceFolder":"xxxx\ApmtWeb\wwwroot","runtimeExecutable":"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe","runtimeArgs":[],"sourceMaps":true,"url":"http://localhost:5031/","trace":{"logFile":"yyyy\Temp\visualstudio-js-debugger.txt"},"port":54798,"launchUnelevated":false,"projectGuid":"cca052fc-e9e7-44d5-8299-28928d665223","userDataDir":"yyyy\Microsoft\VisualStudio\16.0_e9805624\WebTools\F17440DA_BBDA0153","breakOnLoad":true,"smartStep":true,"skipFiles":[],"showAsyncStacks":true,"timeout":10000,"cleanUp":"onlyTab","name":"Visual Studio launch configuration override","type":"pwa-msedge","request":"launch","continueOnDisconnect":true},"seq":2}},"level":0}

The xxxx and yyyy were obscured due to privacy

My launch settings

"ApmtWeb": { "commandName": "Project", "dotnetRunMessages": "true", "launchBrowser": true, "applicationUrl": "http://localhost:5031", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }

I am able to see my web page if I manually type in the URL http://localhost:5031, before the above error shows and forcing it to shutdown.

There is not such setting inside my entire solution as http://localhost:54798, and I can't find any reference to 54798 even if I do a global search.

like image 329
s k Avatar asked Jul 06 '21 02:07

s k


People also ask

How do I fix unable to start debugging on web server?

Restart your Application Pool. Check that your Web Application folder has the right permissions. Make sure that you give IIS_IUSRS, IUSR, or the specific user associated with the Application Pool read and execute rights for the Web Application folder. Fix the issue and restart your Application Pool.

How do I enable debugging in Visual Studio?

In the Visual Studio toolbar, make sure the configuration is set to Debug. To start debugging, select the profile name in the toolbar, such as <project profile name>, IIS Express, or <IIS profile name> in the toolbar, select Start Debugging from the Debug menu, or press F5.

How do I debug in .NET core?

Open the Debug view by selecting the Debugging icon on the left side menu. Select the green arrow at the top of the pane, next to . NET Core Launch (console). Other ways to start the program in debugging mode are by pressing F5 or choosing Run > Start Debugging from the menu.

How to not launch a browser in Visual Studio Code?

How to not launch a browser. Go to the launchSettings.json file in your Visual studio project, look for the following line. This will stop it from launching a browser at all. JavaScript debugging for ASP.Net defines if the browser will open in a new tab or a whole new browser window.

Why is debugging in the browser not working in Visual Studio?

Users have reported that VS can sometimes cache some stale data and cause debugging sessions to fail where it was previously working. If debugging in the browser works, it indicates that this might be the issue. Sorry, something went wrong. What is the standard output displayed for your application?

How to enable razor runtime compilation in ASP NET Core?

To enable Razor runtime compilation till ASP.NET Core 3.1. Till now, if you need to enable Razor runtime compilation, you will follow the below steps. Install the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package. Update the project’s Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation .

Can Visual Studio launch Chrome with DevTools open?

I thought it would be nice to have Visual Studio launch Chrome with the developer tools window already open. After doing some digging, I discovered that Chrome has a command line option to open devtools: --auto-open-devtools-for-tabs. This should be simple enough – just configure a new browser for Visual Studio to use.


Video Answer


3 Answers

When I learned from one of the comments that this is a VS bug, I immediately tried the following:

  1. Close solution
  2. Remove all .vs directories from your project
  3. Launch solution again

Worked for me. Saved me from actually reinstalling VS ;-)

like image 63
Maurice Klimek Avatar answered Nov 15 '22 09:11

Maurice Klimek


You can also disable the debugging of JS by VS, vis the Options menu so you just debug in Chrome (F12). Unchecking this feature, press F5, then stop it, the check it again also fixes the problem.

Such black magic :/ enter image description here

like image 21
Doug Thompson - DouggyFresh Avatar answered Nov 15 '22 08:11

Doug Thompson - DouggyFresh


It is not necessary to delete the whole .vs folder, just go to .vs/project/ and delete the debuggerConfiguration -... json file. It is important to close any browser windows that have remained open before running the project again, otherwise it will recreate the debuggerConfiguration -... json file but it still gives an error.

.vs/project/

like image 23
diego.escada Avatar answered Nov 15 '22 10:11

diego.escada