18

I have Visual Studio 2019 16.6.2 installed, along with the .NET Core 3.1.301 SDK and all the necessary Blazor templates.

If I create a brand new Blazor WebAssmbly application, I can run it from Visual Studio by pressing Ctrl+F5 and it opens a new tab on my active browser window and starts fine.

But when I press F5, a new, separate browser window is opened (which is midly annoying), but the page remains at about:blank for a while until an error message appears in Visual Studio:

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

Unable to launch browser: 
"Could not open wss://localhost:5001/_framework/debug/ws-proxy?browser=wsAFFlocalhostA50821FdevtoolsFbrowserFceed3b95-58ac-470a-b10c-5d139cfd7117": timeout after 60000ms

Whether the Blazor WebAssembly application is "Hosted" or not doesn't make a difference.

I've followed the steps in the Enforce HTTPS in ASP.NET Core, but that made no difference.

If, while waiting for the about:blank window to crash, I manually open the client side url on a browser tab, the app loads and the debugger breakpoints are hit. During the short while before it goes on to crash, if I hit Shift+Alt+D I always get the following error:

Unable to find debuggable browser tab
Could not get a list of browser tabs from http://127.0.0.1:9222/json. Ensure your browser is running with debugging enabled.

Resolution

If you are using Microsoft Edge (80+) for your development, follow these instructions:
Press Win+R and enter the following:

msedge --remote-debugging-port=9222 --user-data-dir="C:\Users\sergi\AppData\Local\Temp\blazor-edge-debug" --no-first-run https://localhost:44372/

I get this each and every time, no matter how often I run the command (having closed all browser instances, rebooted, etc).

This happens in both Edge 84 (Edgium) and Chrome.

I should be able to create a new Blazor WebAssembly app and hit F5 on Visual Studio out of the box. What am I missing?

UPDATE

I've just tried using "old Edge" (EdgeHtml) and Firefox as the debug browser in Visual Studio, and both work as expected (meaning that the application at least starts up when pressing F5). The problem apears to be both Chromium-based browsers then...

UPDATE 2

@JamesHancock posted an easy enough workaround in the comments. For a full resolution (and explanation), I've logged a Github issue with the ASP.NET Core team.

Sergi Papaseit
  • 15,999
  • 16
  • 67
  • 101
  • use Chrome for debugging Blazor - it is more reliable – Mister Magoo Jun 13 '20 at 23:53
  • @MisterMagoo, I've tried with both Chrome and Edge 84 (Edgium). Same result. – Sergi Papaseit Jun 14 '20 at 09:18
  • And did you do the Win+R thing? – H H Jun 14 '20 at 15:15
  • @HenkHolterman, I did, several times. It works for that very moment, only until the `Failed to launch debug adapter` error comes up. But the next time I F5, I'm back to the `about:blank` page. In short, it doesn't solve the problem – Sergi Papaseit Jun 14 '20 at 17:21
  • You said old Edge and Firefox work "as expected" but they won't work as the F5 debug uses the chrome debug protocol... You are not trying to use the old Shift-Alt-D debugging are you? You are correct when you say you should be able to create a new blazorwasm project and F5 debug it - as long as your Visual studio is on the correct version and you are using the latest project template. Does the launchsettings.json file contain an "inspectUri" setting? – Mister Magoo Jun 14 '20 at 22:48
  • @MisterMagoo, When I say Firefox and els Edge work, I mean that the application actually starts when I press F5. That's all I'm asking for atm. I want to be able to hit breakpoints in VS2019; browser debugging is a problem for later. `launchSettings.json` does contain `inspectUri`, and I'm on the latest (non-preview) version of VS and the SDK – Sergi Papaseit Jun 15 '20 at 07:43
  • That is your problem then. inspecturl is required for debugging. Try updating your Blazor wasm template and create another new project, then check for that setting – Mister Magoo Jun 15 '20 at 07:58
  • @MisterMagoo, I think you misread my comment. The tempate I'm using *does already* contain `inpsectUri` on both "BlazorApp1.Client" and "BlazorApp1.Server" `launchSettings.json` files: `"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",` – Sergi Papaseit Jun 15 '20 at 08:01
  • Oh you're right I misread – Mister Magoo Jun 15 '20 at 08:05
  • No problem, I do appreciate you (or indeed anyone) trying to help – Sergi Papaseit Jun 15 '20 at 08:07
  • 1
    One more thing to try, which sounds odd but has worked on other projects that wouldn't debug is to close VS, delete the .vs folder inside the project/solution folders and then retry – Mister Magoo Jun 15 '20 at 08:07
  • @MisterMagoo, I had already tried it, and have done it again for good measure just after reading your comment. Same result. I wonder, why would Firefox and old Edge start up the app, but the Chromium browsers not? Probably because the Chromium browsers try to register the in-broswer debugging of wasm, I guess? – Sergi Papaseit Jun 15 '20 at 08:09
  • Please try to close VS Instance, delete `bin` and `obj` folder, close any Chrome and Edge instance in Task Manager and then restart your blazor project to test again. Besides, change another port for your local Url. – Mr Qian Jun 15 '20 at 09:43
  • @PerryQian-MSFT, thanks, just tried it all; it makes no difference unfortunately. – Sergi Papaseit Jun 15 '20 at 09:58
  • Did your project is from the old version VS? Or you could try to create a new Blazor WebAssembly app in vs2019 and then migrate the old one into it. – Mr Qian Jun 17 '20 at 10:28
  • @PerryQian-MSFT i’ve tried with brand new projects, several new projects, several times – Sergi Papaseit Jun 17 '20 at 10:34
  • So I can repro this issue if I remove the iisSettings and IIS express from profiles. If i put them back it works. (Even if I'm debugging against the project instead) – James Hancock Jun 19 '20 at 16:58
  • 2
    @JamesHancock, you are right, that works for me too. Just removing the `IIS Express` section from `launchSettings.json` on the Server project seems to be enough. VS will then start Kestrel up, apparently, and that works as expected. Good enough workaround for now; you can write this as an answer, if you want... – Sergi Papaseit Jun 21 '20 at 14:28

8 Answers8

9

for me I was missing app.UseWebAssemblyDebugging(); in Startup.Configure(). Hope this helps someone.

blighty
  • 91
  • 1
  • @blightly, thanks, but unfortunately that is not my case. ` app.UseWebAssemblyDebugging();` is already added by default in the projects I've tried, since I am using the latest version of the Blazor Wasm template – Sergi Papaseit Jun 21 '20 at 14:19
  • 1
    I mistakenly commented that line and that makes the error "Failed to launch debug adapter." to show. – d.i.joe Nov 12 '20 at 07:12
  • Thank you, that one helped! I convered my Balzor Server Side to a Client Side app and missed adding this line – t4nky Jan 13 '21 at 21:18
8

Had a project that loaded perfectly fine. Left it for a couple of weeks and when I opened it again tonight, I got this issue.

In launchsettings.json I had this (all default values from the project template, I hadn't changed anything)

 "IIS Express": {
  "commandName": "IISExpress",
  "launchBrowser": true,
  "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
},

I removed this line

  "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",

Pressed F5 and it worked!

And then I inserted it again and it still works.

kristoffer_o
  • 590
  • 5
  • 7
6

After searching for couple of days, I did the following and it worked like charm:

1.Install IE "Microsoft edge"

2.Use IE "Microsoft edge" as your VS. browser (NOT CHROME)

3.Use your application as server (NOT IIS EXPRESS).

Enjoy. enter image description here

Hamdan Dabbas
  • 537
  • 1
  • 5
  • 11
  • Thanks Hamdan. I have been having similar issues with Chrome and local IIS. My webAssembly app works when fine when running without debugging but in debug mode it was exiting with code 0 when i tried to navigate to the Home page, but only when running in debug. I tried your solution above and swapped to Edge, running the app as the server and it works now in debug mode also. There seems to be some issues with Chrome or IIS in debug mode. – Dave Oakley Aug 26 '20 at 13:03
  • This worked for me too. Not cool... should work with Chrome. My stuff is all the latest. .NET 7, VS 17.6.4, Chrome Version 114.0.5735.199. – Victorio Berra Jul 06 '23 at 17:03
5

It appears that the issue is that if you remove the IIS Express section from the launchSettings.json file of your project, that debugging will then fail to work. And this is true even if you're using VS code against the project directly without IIS proxying or VS.net too.

So the solution is to put back the IIS Express section in the launchsettings.json file and not remove it until this is fixed.

James Hancock
  • 3,348
  • 5
  • 34
  • 59
  • 3
    Well, in my case it is actually *removing* the `IIS Express` section from `launchSettings.json` on the Server project that allows me to debug. – Sergi Papaseit Jun 22 '20 at 14:18
2

The problem for me occurs if I select the Configure For HTTPS option when creating the project.


As a workaround,

  1. for an HTTPS configured project changing is settings-sslport, to 0
  2. applicationUrl to only http://localhost:port in launchsettings.json

I think the debug adapter has an underlying security related problem. Good luck!

Flame
  • 6,663
  • 3
  • 33
  • 53
tolgaali
  • 21
  • 3
1

I had this issue as well and I solved it by unticking "Enable SSL" under "Web Server Settings" in project properties.

Obviously disabling SSL is undesirable is nearly all situations but works in my use case.

For a better solution if you're developing on Windows 7 check you have the KB installed that has modern TLS needed for IIS SSL which caused problems with SSL in non chromium browsers.

1

I had the following configurations

  • .NET - 6

  • Visual Studio 2022 Community edition

  • Browser - Google Chrome

I have tried all of the solutions above. But none worked for me. Then I tried changing the browser from Chrome to Firefox. Firefox gave me a different error message and it was pointed towards updating .Net version.

I simply updated VS 2022 from version 17.3.3 to 17.3.5 and problem solved. Hope someone will find this helpful

oshan2csd
  • 393
  • 4
  • 11
0

This sounds extremely naïve but this was the entire problem for me. I didn't notice this line was removed in the diff.

Make sure your main builds and runs the CreateHostBuilder function.

This unfortunately causes the same error above but is not at all directly related.

public static void Main(string[] args)
{
    CreateHostBuilder(args).Build().Run();
}
...
public static IHostBuilder CreateHostBuilder(string[] args)
...
Reap
  • 1,047
  • 13
  • 16