NullReferenceException: Object reference not set to an instance of an object.

David_Ford

Member
Joined
Apr 23, 2017
Messages
12
Programming Experience
10+
This code is blowing up on me, on the last line. No other errors thrown. This is some generated code from a Blazor Server Side app. I can only assume the problem is elsewhere, but I don't know how to find it.

This was running, then I was experimenting around with trying to add CSS code into some html, it blew up, I removed it, and then this started happening. I can't remember doing anything else to cause it. And I have no idea how to use the below messages to start debugging this. Any help?

@page "/"
@namespace BlazorServerApp.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = "_Layout";
}

<component type="typeof(App)" render-mode="ServerPrerendered" />

Here's what was generated in the browser:

  • NullReferenceException: Object reference not set to an instance of an object.​

    • Microsoft.AspNetCore.Components.Routing.Router.Refresh(bool isNavigationIntercepted)​

    • Microsoft.AspNetCore.Components.Routing.Router.SetParametersAsync(ParameterView parameters)​

    • Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)​

    • Microsoft.AspNetCore.Components.RenderTree.Renderer.HandleExceptionViaErrorBoundary(Exception error, ComponentState errorSourceOrNull)​

    • Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToPendingTasks(Task task, ComponentState owningComponentState)​

    • Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)​

    • Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)​

    • Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(ref DiffContext diffContext, int frameIndex)​

    • Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(ref DiffContext diffContext, int frameIndex)​

    • Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(ref DiffContext diffContext, int newFrameIndex)​

    • Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(ref DiffContext diffContext, int oldStartIndex, int oldEndIndexExcl, int newStartIndex, int newEndIndexExcl)​

    • Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, int componentId, ArrayRange<RenderTreeFrame> oldTree, ArrayRange<RenderTreeFrame> newTree)​

    • Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, out Exception renderFragmentException)​

    • Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()​

    • Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)​

    • Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()​

    • Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessPendingRender()​

    • Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(int componentId, RenderFragment renderFragment)​

    • Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged()​

    • Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()​

    • Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()​

    • Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)​

    • Microsoft.AspNetCore.Components.RenderTree.Renderer.HandleExceptionViaErrorBoundary(Exception error, ComponentState errorSourceOrNull)​

    • Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToPendingTasks(Task task, ComponentState owningComponentState)​

    • Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)​

    • Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)​

    • Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderRootComponentAsync(int componentId, ParameterView initialParameters)​

    • Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.CreateInitialRenderAsync(Type componentType, ParameterView initialParameters)​

    • Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.RenderComponentAsync(Type componentType, ParameterView initialParameters)​

    • Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext+<>c__11<TResult>+<<InvokeAsync>b__11_0>d.MoveNext()​

    • Microsoft.AspNetCore.Mvc.ViewFeatures.StaticComponentRenderer.PrerenderComponentAsync(ParameterView parameters, HttpContext httpContext, Type componentType)​

    • Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.PrerenderedServerComponentAsync(HttpContext context, ServerComponentInvocationSequence invocationId, Type type, ParameterView parametersCollection)​

    • Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.RenderComponentAsync(ViewContext viewContext, Type componentType, RenderMode renderMode, object parameters)​

    • Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)​

    • Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, int i, int count)​

    • BlazorServerApp.Pages.Pages__Host.ExecuteAsync() in _Host.cshtml​

      +
      1. <component type="typeof(App)" render-mode="ServerPrerendered" />
    • Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)​

    • Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)​

    • Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)​

    • Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)​

    • Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)​

    • Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)​

    • Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)​

    • Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)​

    • Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()​

    • Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)​

    • Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)​

    • Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)​

    • Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()​

    • Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)​

    • Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)​

    • Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)​

    • Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)​

 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,646
Location
Sydney, Australia
Programming Experience
10+
This is a prime example of why you should be using source control, regardless of the environment you are working in. If something like this happens, you simply rollback your changes and you will be using exactly the same code and accompanying files as before. You should start using source control immediately, whether it be the free Azure DevOps account that Microsoft offer with VS, GitHub or something else.
 

Salrathor1

New member
Joined
May 21, 2022
Messages
1
Programming Experience
1-3
I had a similar error, it was due to creating two pages with the same @page '/profile' when I was moving files into sub-folders.
 

jbenson001

New member
Joined
Aug 5, 2022
Messages
1
Programming Experience
10+
I had a similar error, it was due to creating two pages with the same @page '/profile' when I was moving files into sub-folders.
THANK YOU my friend. I could not figure this out and your answer was EXACTLY my issue. Before I moved my @code{} block to a code behind file, I backed up the page and css to a folder within the project. I didn't think it would be included in the project. Once I saw your answer, I moved the folder outside of my project and BINGO, it was working. It saved me so much time. I was prepared to redo the page or the whole project
THANKS!!!!!!!!!!!!!!!!!!!!!! Jim
 
Top Bottom