'Blazor WebAssembly debug Program.cs

I've tried debugging in both vs code and vs.net 2019 and in both cases debugging everything bug Program.cs works. I'm trying to figure out why configuration isn't working but can't step into the code to see what's going on.

Anyone know how to debug this?



Solution 1:[1]

I'm pretty sure that you can't debug the Program.cs. I don't remember where I read it (it's here), but I think it said that it had something to do with the debugger attaching to the process after everything in the Program.cs file has been executed. What I do is in any place that I want to check variables or values in that file, I write them to the console. The call to Console.WriteLine() in the Program.cs file just writes directly to the browser's developer console. It isn't the easiest way to debug, but it has worked for me several times. I think the same goes for the first razor component page that is loaded, the debugger will not attach till after it's OnInitialized() or OnInitializedAsync() methods have executed, but any subsequent pages after that should stop on breakpoints. Or even if you navigate away from that first page then navigate back it should then hit your breakpoints.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community