17

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
  • 403
  • 1
  • 5
  • 12

8 Answers8

13

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
  • 5,017
  • 2
  • 32
  • 58
  • 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
13

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
  • 163
  • 1
  • 8
5

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

Fred
  • 1,129
  • 1
  • 14
  • 35
  • 1
    Same for me, I changed the browser in Visual Studio 2019 and it started working – BineG Nov 05 '21 at 22:31
  • 1
    Relevant note from the [documentation](https://learn.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
2

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
  • 144
  • 2
  • 11
  • "An alternative to setting a different default browser can be found at this article." What alternative do you mean exactly? There are a lot of answers on that page… – Protector one Dec 14 '22 at 12:55
  • 1
    @Protectorone The accepted answer in the stack overflow page, I linked to, contains a link to an article that describes how to change Visual Studio's default browser. Other answers provide different methods of changing the browser to debug with. – Mort Dec 19 '22 at 06:24
1

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,226
  • 5
  • 16
  • 43
1

I literally just started using Blazor today. One of the first things I did was disable 'Launch browser' because I can't stand that behavior.

Unfortunately I just had to reenable it to get breakpoints working!

I don't yet understand enough to know if this is how I have to do it, or if there's another way.

enter image description here

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
0

I had this issue happen in a Blazor Server application on adding a new page component. I tried all of the above solutions and things really got worse in trying to hit the new page breakpoint. VS 2022 Version 17.6.2. After no success, I updated to VS 2022 17.6.4. Still wouldn't work. I cleaned, deleted .pdb's, closed, restarted vs, etc. many times.

Finally I thought about Excluding the component from the project, then Including the component back to the project. Rebuild and the breakpoint started working.

JClarkCDS
  • 184
  • 2
  • 9