r/Blazor • • Oct 10 '20

Debugging a Blazor application

Why is Blazor so fragile and near impossible to debug?
I'm creating an application, but any minor change causes the Client-side to fail and no longer load, and becomes impossible to debug.
It turns a 1 hour development effort into a week-long affair.
About ready to kick this BS project to the curb and work in React.

0 Upvotes

14 comments sorted by

9

u/affenkonig11b Oct 10 '20

My experience is the exact opposite. You can set proper break points, inspect objects, step into/over/through and generally do everything else you can in a fully fledged IDE with any other c# project. Perhaps if you elaborate on your issue, someone could provide useful input.

2

u/SimpleTruth2753 Oct 10 '20

The latest issue has been resolved, took longer than I expected. Apparently had a page directive pointing to root on two pages. Prior to this, I spent a few days attempting to get out of the box Authentication working on client side. The server-side worked fine, but client side required some additional wiring, and it didn't debug easily. It made that transition difficult. Although I have been able to get through these issues, the task of tracking them down is more difficult than I have experienced with MVC or other .NET applications.

1

u/[deleted] Oct 10 '20

For me the biggest thing to understand is that the client is it's own application. Since it is all started from the server and they share code I assumed they were one application for a while. When that clicked it also made the whole client side of the authentication easier. Although its still a chore. Fortunately I found some good blog posts that helped me a lot.

I've also discovered that whenever you start the Blazor app, make sure you have the developer tools page open. A lot of errors show up in the console log. I'm sure that issue you had with the app not starting would show up in the console log.

4

u/Theotherbutter Oct 10 '20

I agree, I've had a breeze debugging. You're going to have the usual mess when debugging some asynchronous code but that's not specific to Blazor.

1

u/RirinDesuyo Oct 11 '20

And even then it isn't as bad as transpiled async code in JS where breakpoints almost never work properly and if it does it jumps all over the place or steps into the generator code itself.

5

u/Frozen_Turtle Oct 10 '20

I've had a great experience with serverside - are you using clientside?

2

u/SimpleTruth2753 Oct 10 '20

Yes, server-side works fine for me. It's Client-side that's giving me issues.

2

u/lablegmerr Oct 10 '20

1

u/SimpleTruth2753 Oct 10 '20

Hadn't seen this. Thank you for this. I'll definitely make use of this.

1

u/SimpleTruth2753 Oct 10 '20

Current error showing in the console, which is proving difficult to track down:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

Unhandled exception rendering component: Sequence contains no elements

System.InvalidOperationException: Sequence contains no elements

at System.Linq.Enumerable.First[TSource] (System.Collections.Generic.IEnumerable`1[T] source) <0x2f877b0 + 0x0001e> in <filename unknown>:0

atBlazorClient.Client.ApiAuthenticationStateProvider.GetClaimsDetails (System.String type) [0x000e2] in E:\Repo\BlazorClient\Client\ApiAuthenticationStateProvider.cs:60

at BlazorClient.Client.Shared.LoginDisplay.OnInitializedAsync () [0x0002a] in E:\Repo\BlazorClient\Client\Shared\LoginDisplay.razor:34

at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2bf8f20 + 0x0013a> in <filename unknown>:0

at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x2dbf148 + 0x000b6> in <filename unknown>:0

1

u/cjb110 Oct 11 '20

Sounds like your rendering a list/collection, that's either empty or not initialized.

1

u/sr955 Oct 15 '20

This is most like due to this: If you are rendering a list make sure you say List<string> list = new List<string>() when you declare it.

1

u/TheTitanGesticulated Oct 25 '20

I’ve had the same experience when running WASM directly using MS’s “dev server” which is still absolute shit as of .NET 5 RC2. Debug as a hosted app, should solve that problem, but you’ll find new ones too. Unfortunately as stable as Blazor is right now, the tooling is complete garbage still. Also quick tip, because of the garbage tooling, every time you rename a razor file, or move to a separate folder. Delete your entire bin and obj folder. Tooling doesn’t have file system watcher in place and doesn’t recognize the changes without a delete or restart of VS.

1

u/[deleted] Oct 26 '20

After I updated visual studio I stopped having that problem.