11

Breakpoints won't hit in ASP.NET Core 3.1, Blazor Webassembly project.

I have a solution with a single Blazor Webassembly project which I run locally.

When placing a breakpoint in a .cs file it says:

"The breakpoint will not currently be hit. A copy of Startup.cs was found in blazor-devserver.dll, but the current source code is different from the version built into blazor-devserver.dll.

To allow this breakpoint to be hit, click the 'Settings...' button that appears, then click 'Location', 'Allow the source code to be different from the original.' ..."

This seems strange to me because I don't deploy, I just hit F5 in Visual Studio so I don't see how the code can be different.

Wen the breakpoint is placed in a .razor file it says:

"The breakpoint will not currently be hit. No symbols have been loaded for this document"

In the modules window, symbols have been loaded for all entries.

It worked fine until recently. Only thing I did was installing Microsoft Code Anlysis 2019 (removed it again).

Dabriel
  • 303
  • 1
  • 4
  • 12

6 Answers6

8

Blazor Webassembly is still in preview stage hence you cannot debug the cs file directly. Debugging is supported via Chrome only. The details are documented here.

ViRuSTriNiTy
  • 4,772
  • 2
  • 29
  • 54
  • I've been debugging it for the last days without any issues. Edit: the .razor files I mean – Dabriel Nov 14 '19 at 10:49
  • @Niko Are you sure you have a Webassembly project? You might also facing a cache issue. Try to disable it by opening the Chrome developer console, tab Network and check "Disable cache". – ViRuSTriNiTy Nov 14 '19 at 10:55
  • I used the Blazor Webassembly template when creating the project (not Blazor Server). It's also possible to do System.Console.WriteLine() to the browser console, so I'm pretty sure it's Blazor Webassembly. I ticked "Disable cache" on in devtools but it doesn't change anything. – Dabriel Nov 14 '19 at 11:00
  • @Niko I was wondering how you achieved debugging a cs file directly. Even the github issue for debugging client-side Blazor is still open and under development. See https://github.com/aspnet/AspNetCore/issues/9035 – ViRuSTriNiTy Nov 14 '19 at 11:09
  • I edited my previous comment, it are the .razor files which I debugged and I'm 100% positive it worked. I did put breakpoints in "OnInitializedAsync()" to inspect the response of my webapi method and it worked fine. – Dabriel Nov 14 '19 at 11:12
  • Do you have your project under version control? You could then just execute a fresh checkout without the code analysis change to verify whether its the newly added dependency causing the issue. – ViRuSTriNiTy Nov 14 '19 at 11:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/202328/discussion-between-virustrinity-and-niko). – ViRuSTriNiTy Nov 14 '19 at 11:16
  • This one is not in source control because it's a tryout to explore Blazor but I did made some manual backups and restored them. Didn't resolve the issue. – Dabriel Nov 14 '19 at 11:20
  • How about starting from scratch with a new project created from the Blazor Webassembly template? Perhaps debugging is working again... – ViRuSTriNiTy Nov 14 '19 at 11:25
  • Did that, doesn't seem to work either. I did copy the project from a Blazor server project though. I'm really starting to wonder if I mixed things up that badly and was debugging the server project all the time... – Dabriel Nov 14 '19 at 11:39
  • 1
    I'll be working further on the Blazor server project. After reading the documentation on the link you provided I think I must of been quite distracted. Wasted whole morning on troubleshooting this. I will mark this as an answer, thanks a lot for your time @ViRuSTriNiTy – Dabriel Nov 14 '19 at 11:45
8

I know this does not answer directly this question but this was only question that pop up on google. I couldn't get symbols loaded for blazor client (asp.net core hosted) when debugging. It turned out that I was missing one line in launchSettings.json in asp.net core server app.

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

Hope this will help someone.

Jiří Kotásek
  • 103
  • 1
  • 6
  • Thank you, that is very helpful, I struggled with this issue after migrating from `Blazor.Server` to `Blazor.WebAssembly` in .NET 6. – rvnlord Mar 14 '22 at 16:05
5

Using Blazor and .net 5 switching from FireFox to Google Chrome did the trick for me.

Fred
  • 987
  • 1
  • 9
  • 32
  • 1
    Same for me, I changed the browser in Visual Studio 2019 and it started working – BineG Nov 05 '21 at 22:31
  • Relevant note from the [documentation](https://docs.microsoft.com/en-us/aspnet/core/blazor/debug?view=aspnetcore-6.0&tabs=visual-studio) under the "Prerequisites" section: "Debugging requires either of the following browsers: Google Chrome (version 70 or later) (default) ; Microsoft Edge (version 80 or later)" – Preston Maness Apr 15 '22 at 22:17
3

You can now Debug the Blazor WebAssembly using the Preview Version of Visual Studio 2019. You can check the details here

Praadeep
  • 79
  • 4
1

I found that setting Windows to use Edge as a default browser and configuring the project to launch the browser, allows Visual Studio to configure and connect to the Edge browsing session.

  • Manually starting Edge did not work.
  • Starting Edge and hitting Shift+Alt+D did not work.
  • Starting Edge with the command line "msedge --remote-debugging-port=9222 --user-data-dir="C:\Users\MyUserProfile\AppData\Local\Temp\blazor-edge-debug" --no-first-run https://localhost:12345/" did not work.
  • Configuring firewall to accept incoming connections on TCP port 9222 did not work.

An alternative to setting a different default browser can be found at this article. This works just as well as setting Edge as the default browser.

I assume the same method can be used for Chrome, but I haven't tried it.

Mort
  • 140
  • 2
  • 9
0

Also using "inspectUri" in all profiles breakpoint still not to be hit for Razor components. I used as workaround to set "sslPort": 0 in launchsettings but now I can't use it otherwise I can't login in my Blazor Webassembly project. I'm working on a hosted Blazor WebAssembly App, configured for HTTPS, with authentication.

MMG
  • 3,105
  • 5
  • 11
  • 38