In a client-side Blazor app the C# breakpoints are disabled and not hit.
Is there a way to attach or enable
the debugger?
In a client-side Blazor app the C# breakpoints are disabled and not hit.
Is there a way to attach or enable
the debugger?
For those who like some pictures, here's a step by step using Visual Studio 16.4 preview (.NET Core 3.1 preview 2) & Chrome version 78.
Start up the app using a debug profile. E.g.
After site loads, and with the cursor focus on the chrome tab press "Shift+Alt+D".
Chrome will open a new tab showing "Unable to find debuggable browser tab". Find the first instance of the message "Press Win+R". Copy the full line below which starts "chrome -- remote-debugging-port..."
Hit "Win+R" and paste in the text you just copied and hit enter. A new Chrome window will open..
For the second time, press "Shift+Alt+D" and you should now see something a bit more promising..
From here, set a few breakpoints, E.g.
Go back to the tab running Blazor app, trigger your breakpoint. From here you can press F10 for a single step, and F8 for resume. Inspect locals via the "Scope" window as shown.
Yes there's a way to debug your client side c# code:
In the latest version of the blazor preview functionality has being added to debug client side code with visual studio. Follow the instructions on the link below on how to upgrade your solution and use the debugger.
https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-3-release-now-available/
This is a known issue in Blazor projects at this time. The debugger launches slower/quicker than the project assembly and doesn't have time to "see" the assembly. Here is my fix until they solve this. I add a delay in Program.cs so that when the project launches in debug mode, it gives the debugger time to attach properly. I used 5000 ms but you may have to increase this value if your machine is slower than mine.
public class Program
{
private static async Task DebugDelayAsync()
{
#if DEBUG
await Task.Delay(5000);
#endif
}
public static async Task Main(string[] args)
{
await DebugDelayAsync();
(...)
}
}
I just hit this issue due to using Brave as a browser, As soon as I told Visual Studio to use Chrome or Edge the client breakpoints suddenly started working.
The good news is that now (August 2020) you can use Visual Studio 2019 V16.6 or higher to debug the client side Blazor code! To do so, update the launchSettings.json file in the startup project to include the following inspectUri property in each launch profile:
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
Source: https://learn.microsoft.com/en-us/aspnet/core/blazor/debug?view=aspnetcore-3.1&tabs=visual-studio
It's only available in Google Chrome and Microsoft Edge. Also in Visual Studio 2022, you have to enable Script Debugging. Then you are able to debug and the breakpoint will be hit.
It's an old post, but I had this same symptom with a different fix and couldn't find a great answer posted elsewhere.
If you are using Visual Studio in Windows to debug and have set the HTTP_PROXY
/HTTPS_PROXY
environment variables, it turns out that VS debugging needs to use the proxy. That seems to mean that you need to also set NO_PROXY
env var to let the debugger connect to localhost...
NO_PROXY=localhost,127.0.0.1
After I did that, client-side debugging in my Blazor WASM app worked.
There are 5 different things that need to be set properly in order for this to work, at least in Visual Studio 2022.
Make sure you're in Debug mode when you run the project.
Select either Chrome or Edge as the Web Browser
, as below.
Set the Script Debugging
menu item to Enabled
, as below.
Make sure the Launch browser
option is checked (true). This can be done either through the <Project Name> Properties
menu (as shown above) or via the Properties\launchSettings.json
file directly. You can't debug your code through an already running browser.
In the launchSettings.json
file, enter this:
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
This is an example of a minimal launchSettings.json
file:
{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5127"
}
...
My problem was fixed by enabling "Enable .NET Framework source stepping" This automatically disables the "Enable Just My Code" see VS Options dialog box
This is the problem of the Visual Studio version. Update your VS and your problem will be solved. good luck
This issue has been addressed in .NET 7 Framework. You can just add the debugger and the breakpoint will get hit.
© 2022 - 2024 — McMap. All rights reserved.