blazorblazor-server-side

How can I avoid TaskCanceledException by RemoteNavigationManager


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?


Solution

  • 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