Closed springy76 closed 9 months ago
Thanks for contacting us.
We're moving this issue to the .NET 8 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.
Having rolled out our software with update net6->net7 our SEQ counter for (important) circuit crashes now increased from 20-40 per day to 1600-2000 per day.
One more callstack seems to be new, too:
Microsoft.JSInterop.JSDisconnectedException: JavaScript interop calls cannot be issued at this time. This is because the circuit has disconnected and is being disposed.
at Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSRuntime.BeginInvokeJS(Int64 asyncHandle, String identifier, String argsJson, JSCallResultType resultType, Int64 targetInstanceId)
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
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()
I am having the same issue, everything was working just fine. After shut down and restart then it started. Microsoft Edge will not even display anything and the error message comes to the console. Firefox displays the home but when you click the Login button then after a minute or so the error will show in console. Below is the error.
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7190
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5284
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Home\AppDevelopment\CLR\macOS\BMCL.LawReport.Web\BMCL.LawReport.Web
fail: Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager[4]
Navigation failed when changing the location to https://localhost:7190/Identity/Account/Register
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.<>cDisplayClass13_0.<
Observations: Microsoft Edge is not able to display the home page at all. Firefox is able to display the home page, you are able to click login and fill in the form but when you click the blue login button, a few minutes later it logs the above errors. Google Chrome, Brave, Opera and Vivaldi behave like Firefox but they do not log the error to the console.
Visual Studio Community edition version 17.4.2 Windows 11 Pro 22H2 Build 22621.900
I did windows update yesterday. That is the only thing I did that from then on it started given the error above. I hope the updated information helps.
Also running into a simalar exception with MircosoftIdentity
Message: Navigation failed when changing the location to https://..../MicrosoftIdentity/Account/SignOut
Callsite: Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.NavigateToCore
Exception: 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()
Upon further investigation, I realized it was coming from the OnPostAsync method. I found out that Microsoft SQL server had stopped after windows update. Restarting SQL server in the services applet stopped the error and everything was okay. If in your appsettings.json file you use IP Address and you move to another subnet, you may experience similar frustration. Correction to the new IP Address will resolve the issue.
But strangely when I put the whole code block in a try catch nothing happened. It couldn't move past the following code which is the problematic code when SQL Server is offline and you don't know it's offline:
var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
Now, my question is: How do you report to your user if something has gone wrong and send a graceful message like "No internet connection or Database is down?" Below is the code in a try/catch:
` public async Task
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
if (ModelState.IsValid)
{
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
_logger.LogInformation("User logged in.");
return LocalRedirect(returnUrl);
}
if (result.RequiresTwoFactor)
{
return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
}
if (result.IsLockedOut)
{
_logger.LogWarning("User account locked out.");
return RedirectToPage("./Lockout");
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return Page();
}
}
// If we got this far, something failed, redisplay form
return Page();
}
catch (Exception ex)
{
ErrorMessage = ex.Message;
return Page();
}
}
`
@springy76 @mkArtakMSFT any updates or known workarounds for this one?
i have the same issue. I check if the user is authenticated, if not i redirect to the login page.
My App.razor looks like this.
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (!IsAuthenticated())
{
<h1>Hi,</h1>
<p>You need to login</p>
<a href="login?redirectUri=@NavigationManager.Uri">Login now</a>
}
else
{
<h1>Hi,</h1>
<p>You have no access rights</p>
<p>Contact an administrator</p>
}
</NotAuthorized>
<Authorizing>
<p>Loading...</p>
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>404 - Not Found</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
@code {
private bool IsAuthenticated()
{
var authState = AuthenticationStateProvider.GetAuthenticationStateAsync().Result;
var user = authState.User;
if (user.Identity!.IsAuthenticated)
{
return true;
}
else
{
try {
NavigationManager.NavigateTo($"login?redirectUri={NavigationManager.Uri}", true, true);
}
catch { }
return false;
}
}
}
Error Navigation failed when changing the location to login?redirectUri=https://domain.com/application/
System.Threading.Tasks.TaskCanceledException: A task was canceled.
File "JSRuntime.cs", in async ValueTask<TValue> JSRuntime.InvokeAsync<TValue>(long targetInstanceId, string identifier, object[] args)
File "JSRuntimeExtensions.cs", in async ValueTask JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, string identifier, params object[] args)
File "RemoteNavigationManager.cs", in async void RemoteNavigationManager.NavigateToCore(string uri, NavigationOptions options)+PerformNavigationAsync(?)
It's a Blazor Server Application, .NET 7
@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))
@springy76 thanks, that looks way better. Just for future readers, the awaited state is part of the <AuthorizeRouteView>
not of <NotAuthorized>
.
It should look like this:
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" Context="authState">
<NotAuthorized>
@if (!IsAuthenticated(authState))
@Schtailian now it looks wrong to me - to my knowledge Context
at the component level only makes sense when using ChildContent
implicitly (when of type RenderFragment<T>
).
Just for future readers, the state part definitely is part of the NotAuthorized
parameter, see https://github.com/dotnet/dotnet/blob/main/src/aspnetcore/src/Components/Authorization/src/AuthorizeRouteView.cs#L52
@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))
Hi,
since i changed my IsAuthenticated
the way @springy76 suggested i get no more Navigation failed when changing the location to...
errors.
Having rolled out our software with update net6->net7 our SEQ counter for (important) circuit crashes now increased from 20-40 per day to 1600-2000 per day.
One more callstack seems to be new, too:
Microsoft.JSInterop.JSDisconnectedException: JavaScript interop calls cannot be issued at this time. This is because the circuit has disconnected and is being disposed. at Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSRuntime.BeginInvokeJS(Int64 asyncHandle, String identifier, String argsJson, JSCallResultType resultType, Int64 targetInstanceId) at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args) 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()
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?
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.
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.
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
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?
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.
@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.
Why is this issue closed? I updated to .NET 8.0.3 and still these Exceptions occure
also still occurs for me.
also still occurs for me. https://architecture.blazorserver.com/
Message
Navigation failed when changing the location to "/pages/authentication/login"
Exception
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.<
.Net 8.0.202 After the Token expires, perform a jump to report an error
fail: Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager[4]
Navigation failed when changing the location to /account/login
Microsoft.JSInterop.JSDisconnectedException: JavaScript interop calls cannot be issued at this time. This is because the circuit has disconnected and is being disposed.
at Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSRuntime.BeginInvokeJS(Int64 asyncHandle, String identifier, String argsJson, JSCallResultType resultType, Int64 targetInstanceId)
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
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.<>cDisplayClass13_0.<
It still occurs for us as well, albeit at a significantly reduced rate. Could you take another look @mkArtakMSFT ?
Thanks =)
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.<
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.<
Still occurs for me also. What's odd is that I seem to only get this when on iOS & iPadOS.
Happening to me as well, this shouldn't be closed.
Is there an existing issue for this?
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>
inLoginDisplay.razor
.Wait a minute (or maybe 2) then 2 errors are logged to console (or external logging apps like SEQ):
Exceptions (if any)
TaskCancelledException
.NET Version
7.0.0