Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 241
James Hancock Avatar asked Jun 19 '20 17:06

James Hancock


People also ask

Does Blazor use C#?

Blazor apps are composed of reusable web UI components implemented using C#, HTML, and CSS. Both client and server code is written in C#, allowing you to share code and libraries.

What is AOT compilation Blazor?

Ahead-of-time (AOT) compilation. Blazor WebAssembly supports ahead-of-time (AOT) compilation, where you can compile your . NET code directly into WebAssembly. AOT compilation results in runtime performance improvements at the expense of a larger app size.


Video Answer


1 Answers

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.

like image 173
JG222 Avatar answered Oct 13 '22 14:10

JG222