How can I avoid TaskCanceledException by RemoteNavigationManager

David Thielen 3,116 Reputation points
2024-03-09T14:03:15.4966667+00:00

Hi all;

I have a Blazor server app and every couple of minutes I get the following in my logs:

Error 12:09:54 [] Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager - Navigation failed when changing the location to https://louishowe-dev.azurewebsites.net/Identity/Account/Login TaskCanceledException: A task was canceled.
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
   at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
   at Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.<>c__DisplayClass13_0.<<NavigateToCore>g__PerformNavigationAsync|0>d.MoveNext()
Error 12:09:54 [] Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost - Unhandled exception in circuit 'GdWjUPhwt9bdljJjyKo0M-eVaVKtacUkhqCtNuwOg-s'. TaskCanceledException: A task was canceled.
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
   at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
   at Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.<>c__DisplayClass13_0.<<NavigateToCore>g__PerformNavigationAsync|0>d.MoveNext()

The program continues to run fine and the user sees no issue. But exceptions are generally bad news. What's going on here and how do I avoid this?

thanks - dave

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,577 questions
{count} votes

6 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 65,131 Reputation points
    2024-05-15T21:03:37.3766667+00:00

    Your issue is that remote navigation, redirects the browser to a new page. in prep a clean Blazor shutdown is attempted. it needs to close the signal/r connection, and unload the Blazor app instance. this requires all threads exit, typically via a cancellation token. any dangling threads need to be killed.

    in your case Blazor is redirecting to login. beside there a minimum side effects when this happens.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.