C
C#2mo ago
hunterlan

UseExceptionHandler is not working is Blazor

I want to show any unhandled errors in Blazor. I added UseExceptionHandler, but when I try to test it, it shows nothing. I do with "ASPNETCORE_ENVIROMENT: Production" value. I know about ErrorBoundary approach, but it's not what I want to do.
2 Replies
hunterlan
hunterlanOP2mo ago
Oh, and also, it throws some kind of error, but I found a little piece of information about it:
2025-03-06 15:11:51.148 +01:00 [ERR] An exception was thrown attempting to execute the error handler.
System.InvalidOperationException: 'RemoteNavigationManager' already initialized.
at Microsoft.AspNetCore.Components.NavigationManager.Initialize(String baseUri, String uri)
at Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.Initialize(String baseUri, String uri)
at Microsoft.AspNetCore.Components.Endpoints.EndpointHtmlRenderer.InitializeStandardComponentServicesAsync(HttpContext httpContext, Type componentType, String handler, IFormCollection form)
at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<<InvokeAsync>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Builder.ServerRazorComponentsEndpointConventionBuilderExtensions.<>c__DisplayClass1_1.<<AddInteractiveServerRenderMode>b__1>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.HandleException(HttpContext context, ExceptionDispatchInfo edi)
2025-03-06 15:11:51.148 +01:00 [ERR] An exception was thrown attempting to execute the error handler.
System.InvalidOperationException: 'RemoteNavigationManager' already initialized.
at Microsoft.AspNetCore.Components.NavigationManager.Initialize(String baseUri, String uri)
at Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.Initialize(String baseUri, String uri)
at Microsoft.AspNetCore.Components.Endpoints.EndpointHtmlRenderer.InitializeStandardComponentServicesAsync(HttpContext httpContext, Type componentType, String handler, IFormCollection form)
at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<<InvokeAsync>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Builder.ServerRazorComponentsEndpointConventionBuilderExtensions.<>c__DisplayClass1_1.<<AddInteractiveServerRenderMode>b__1>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.HandleException(HttpContext context, ExceptionDispatchInfo edi)
Clint
Clint2mo ago
What versions of ASP.NET and Blazor are you using? It looks like a GitHub issue (https://github.com/dotnet/aspnetcore/issues/49854) was opened that seems to be related to error pages not working when in production mode, and it looks like that might have been resolved / the related issues & PR discussions bring up some possible workarounds.
GitHub
[Blazor] Error page support · Issue #49854 · dotnet/aspnetcore
When I try to trigger the exception handler middleware by throwing an exception from a Blazor Web App I get an exception about RemoveNavigationManager being already initialized. Repro steps: Instal...

Did you find this page helpful?