How can I avoid TaskCanceledException by RemoteNavigationManager

David Thielen 2,331 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,427 questions
{count} votes

6 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  5. David Thielen 2,331 Reputation points
    2024-05-15T16:32:52.8966667+00:00

    From Microsoft support:

    1. Increase the SignalR message size and disable the JSRuntime call timeouts, as these could be possible causes of the exception. You can find more details on how to do this in the attached KB article.

    Blazor.NET: What causes "A task was canceled" within JavaScript - Stack Overflow

    1. Make sure that the JavaScript methods you call via JSRuntime always return a value, and check your network connection for any interruptions. These could also affect the JSRuntime calls. Here are some forums where other developers have discussed similar problems.

    (BlazorServer) each navigation to external logs 2 errors a minute later · Issue #45267 · dotnet/aspnetcore · GitHub

    Trouble with NavigateTo within OnInitialized · Issue #13582 · dotnet/aspnetcore · GitHub

    0 comments No comments