Hello - here's something a better error indication would be really helpful.
In short, in Blazer server side app w/ .Net 6.0 long term support, the following problem occurs while under development with Visual Studio 2022 - 17.6.3.
Accept the default sample app (the one with counter with purple design)
Create a new Blazor cshtml page.
using @page at the top, have the same string across different cshtml files
for example,
@page "/pineapple" at a.cshtml,
@page "/pineapple" at b.cshtml
and so on..
Then the project crashes in an unexpected way, throwing the Null Reference exception at _Home.cshtml
Desired solution:
Please give the user a more friendly error like "Duplicate routing by @page exists. @page in each Razor page must be unique." or something. You may or may not be able to repro right away, but this exists and the community has learnt how to deal with it (see link here), but this problem would categorically just do away if VS could check for duplicating @page in the first place.
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.AspNetCore.Components
StackTrace:
at Microsoft.AspNetCore.Components.Routing.Router.Refresh(Boolean isNavigationIntercepted)
at Microsoft.AspNetCore.Components.Routing.Router.d56.MoveNext()
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.HandleExceptionViaErrorBoundary(Exception error, ComponentState errorSourceOrNull)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToPendingTasks(Task task, ComponentState owningComponentState)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange1 oldTree, ArrayRange1 newTree)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessPendingRender()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(Int32 componentId, RenderFragment renderFragment)
at Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged()
at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.d20.MoveNext()
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.HandleExceptionViaErrorBoundary(Exception error, ComponentState errorSourceOrNull)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToPendingTasks(Task task, ComponentState owningComponentState)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.d39.MoveNext()
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.d17.MoveNext()
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.d8.MoveNext()
at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c11`1.<b11_0>d.MoveNext()
at Microsoft.AspNetCore.Mvc.ViewFeatures.StaticComponentRenderer.d4.MoveNext()
at Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.d11.MoveNext()
at Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.d6.MoveNext()
at Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper.d21.MoveNext()
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<g__Awaited|0_0>d.MoveNext()
at DBAgentBlazorUI.Pages.PagesHost.d__7.MoveNext() in C:\source\DBAgent2023\DBAgentBlazorUI\Pages_Host.cshtml:line 8
This exception was originally thrown at this call stack:
[External Code]
DBAgentBlazorUI.Pages.Pages__Host.ExecuteAsync() in _Host.cshtml
This issue has been moved from a ticket on Developer Community.
Hello - here's something a better error indication would be really helpful.
In short, in Blazer server side app w/ .Net 6.0 long term support, the following problem occurs while under development with Visual Studio 2022 - 17.6.3.
@page "/pineapple" at a.cshtml, @page "/pineapple" at b.cshtml
and so on..
Then the project crashes in an unexpected way, throwing the Null Reference exception at _Home.cshtml
Desired solution: Please give the user a more friendly error like "Duplicate routing by @page exists. @page in each Razor page must be unique." or something. You may or may not be able to repro right away, but this exists and the community has learnt how to deal with it (see link here), but this problem would categorically just do away if VS could check for duplicating @page in the first place.
see the stack overflow here https://stackoverflow.com/questions/69379462/blazor-nullreferenceexception-in-host-cshtml-when-loading-a-page-with-editform
System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=Microsoft.AspNetCore.Components StackTrace: at Microsoft.AspNetCore.Components.Routing.Router.Refresh(Boolean isNavigationIntercepted) at Microsoft.AspNetCore.Components.Routing.Router.d56.MoveNext()
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.HandleExceptionViaErrorBoundary(Exception error, ComponentState errorSourceOrNull)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToPendingTasks(Task task, ComponentState owningComponentState)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRanged 20.MoveNext()
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.HandleExceptionViaErrorBoundary(Exception error, ComponentState errorSourceOrNull)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToPendingTasks(Task task, ComponentState owningComponentState)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.d39.MoveNext()
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.d 17.MoveNext()
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.d8.MoveNext()
at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c11`1.<b11_0>d.MoveNext()
at Microsoft.AspNetCore.Mvc.ViewFeatures.StaticComponentRenderer.d4.MoveNext()
at Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.d 11.MoveNext()
at Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.d6.MoveNext()
at Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper.d 21.MoveNext()
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<g__Awaited|0_0>d.MoveNext()
at DBAgentBlazorUI.Pages.Pages Host.d__7.MoveNext() in C:\source\DBAgent2023\DBAgentBlazorUI\Pages_Host.cshtml:line 8
1 oldTree, ArrayRange
1 newTree) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException) at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception) at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue() at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessPendingRender() at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(Int32 componentId, RenderFragment renderFragment) at Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged() at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync() at Microsoft.AspNetCore.Components.ComponentBase.This exception was originally thrown at this call stack: [External Code] DBAgentBlazorUI.Pages.Pages__Host.ExecuteAsync() in _Host.cshtml
Original Comments
Feedback Bot on 6/25/2023, 11:06 PM:
(private comment, text removed)
Feedback Bot on 6/26/2023, 11:30 PM:
(private comment, text removed)
Original Solutions
(no solutions)