aspnetcore: (BlazorServer) each navigation to external logs 2 errors a minute later

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Each time you leave the blazor circuit a minute later two exceptions are logged.

Expected Behavior

zero errors in log when no one does wrong things.

Steps To Reproduce

Run original sample created by dotnet.exe new blazorserver --name BlazorServerTemplate --output . -f net7.0 --auth Individual --use-program-main

On top right click on “Login” which is <a href="Identity/Account/Login">Log in</a> in LoginDisplay.razor.

Wait a minute (or maybe 2) then 2 errors are logged to console (or external logging apps like SEQ):

fail: Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager[4]
      Navigation failed when changing the location to https://localhost:7206/Identity/Account/Login?returnUrl=~/counter
      System.Threading.Tasks.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()
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'XaCjYqsnL_QC9xVVeKm9IEojYbj1uBcoSgjuyHwtR7U'.
      System.Threading.Tasks.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()

Exceptions (if any)

TaskCancelledException

.NET Version

7.0.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 10
  • Comments: 27

Commits related to this issue

Most upvoted comments

Thanks for contacting us.

We’re moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it’s very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

Still occurs for me also. What’s odd is that I seem to only get this when on iOS & iPadOS.

Why is this issue closed? I updated to .NET 8.0.3 and still these Exceptions occure

Happening to me as well, this shouldn’t be closed.

I am also dealing with this, and have come to find this is a known issue? I’m not sure I’m a fan of the Js workaround… <NavLink href="MicrosoftIdentity/Account/SignIn">Sign In</NavLink>

04/15/2024 14:11:42 Navigation failed when changing the location to “https://localhost:xxxx/MicrosoftIdentity/Account/SignIn” System.Threading.Tasks.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()

04/15/2024 14:11:42 Unhandled exception in circuit ‘“xxxxxxxxx”’. System.Threading.Tasks.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()

also still occurs for me.

@HoofedEar Thanks, your solution with JSRuntime works! 😃

For issuetracker: I noticed that this bug happens only in Firefox browser. No errors with Chromium based browsers.

I still get these. I think they might happen with this component https://github.com/Blazored/Toast, but i haven’t tried so far. @springy76 do you use anything similar?

@Schtailian no, it’s just the unchanged template created by dotnet.exe new blazorserver --name BlazorServerTemplate --output . -f net7.0 --auth Individual --use-program-main

and still the same with net8 + Blazor WebApp + Individual Auth … multiple errors in console after just some simple clicks

yep, still the same with .net 8 also for me. @mkArtakMSFT is there anything we can do, to prevent this?

Leaving this comment here for a fix that worked for me.
I kept getting the above NavigationManager exceptions when trying to interact with my custom Authentication middleware that handles my login/logout requests. This was what I was previously using to trigger a login (inside of my Blazor page, in the code section):

NavManager.NavigateTo(returnUrl != null ? $"/middleware-login?key={key}&returnUrl={returnUrl}" : $"/middleware-login?key={key}", true, true);

After replacing it with this:

@inject IJSRuntime JSRuntime
...
await JSRuntime.InvokeVoidAsync("window.location.assign", returnUrl != null ? $"/middleware-login?key={key}&returnUrl={returnUrl}" : $"/middleware-login?key={key}");

I stopped getting those exceptions from NavigationManager. Hope this is helpful to others!

EDIT: Also, I noticed that the aforementioned exceptions appear if you try to navigate to a page that doesn’t exist.

@springy76 Sorry, yea you totally write. I was to impatient with intellisense 🙉 it’s like in your example but with context instead of content.

<NotAuthorized Context="authState">
    @if (!IsAuthenticated(authState))

@Schtailian just a side note regarding your code snippet: Do not use the Result property of Tasks to “await” a task, all sorts of deadlocks might happen using such code. The NotAuthorized renderfragment already transports the awaited AuthenticationState by context variable, just pass it around:

                <NotAuthorized Content="authState">
                    @if (!IsAuthenticated(authState))