Debugging is not working in VS Mac - Blazor web app

Viewed 819

I am learning C# and bought the Head First book. It has an exercise of creating a simple Blazor app and then start debugging it. Here is a walkthrough of such exercise (with a timestamp): https://youtu.be/i_w-2pIqxj4?t=972

In my code in Pages → Index.razor I put a breakpoint to the if statement enter image description here

and click on "Run" → "Start Debugging". After my app opening in a browser, I click on a button but nothing happens in Visual Code: https://jmp.sh/xuolRVk

If I run a regular console app and debug it I can use Debugger with no issues.

  1. I tried Google Chrome, Mozilla Firefox, Opera, Microsoft Edge.
  2. macOS Catalina 10.15.6 (19G2021)
  3. VS for Mac Community 8.8.4 build 30
2 Answers

I ran into the exact same issue while following this book. I added the delay, as noted in the previous solution, but this did not work for me.

Finally, after trying many other potential solutions found online, what worked was this:

  1. Creating my solution in the default directory (instead of changing it to something else) that Visual Studio provides:

    /Users/user_name/Projects
    
  2. Not 100% sure if this was necessary, but I also ran these commands:

    sudo dotnet dev-certs https --trust
    sudo dotnet dev-certs https --clean
    

I hope this helps someone out there!

I have come across the exact same issue with Head First C#!

The issue for me seems to have been that the debugger takes longer to load than the programme itself, so it is not launched by the time the breakpoint is hit. Microsoft's docs page on Debugging ASP.NET Core Blazor Web Assembly suggests adding a delay.

I have added in a delay in the OnInitialized function:

protected override void OnInitialized()
{
    System.Threading.Thread.Sleep(10000);
    SetUpGame();
}

This seems to have my breakpoints working!

Related