Posted: 26/03/2021
Error When Incorrect Post Uri Used
I noticed that when an invalid Uri is used to access one of these Blazor based Blog posts, we don't get a 404 error (see Why Can I Not Jump Direct To A Blog Post? ) we get an error in the console thrown by the code base.
What is going on? Off to the debugger we go.
Yikes, I cannot debug it!!
The error is :
blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Arg_NullReferenceException System.NullReferenceException: Arg_NullReferenceException at MarkOliverBlog.BlogPostReader.PopulateSingleBlogContents(String title) at MarkOliverBlog.BlogPostReader.GetPost(String title) at MarkOliverBlog.Pages.BlogPage.OnParametersSetAsync() at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
Ok, I have a NULL somewhere in the code, but that is not really the concern, why can I not debug it?
The clue here is the "OnParametersSetAsync()"
As per the
docs
(Note we are on .NET 5 here):
Hit breakpoints during app startup before the debug proxy is running. This includes breakpoints in Program.Main (Program.cs) and breakpoints in the OnInitialized{Async} methods of components that are loaded by the first page requested from the app.
Right, the problem is I cannot debug in the app startup routine.
So I should check lifecycle of the app which should tell me where I can put this code correctly.
UPDATE - Hang on, this is not the same step, this is the step after that. I should be able to debug this!!!
I'll come back to you!
Thanks for reading this post.
If you want to reach out, catch me on Twitter!
I am always open to mentoring people, so get in touch.