C#C
C#3y ago
10 replies
dreadfullydistinct

❔ NavigationManager: TaskCancelledException

I've got an OAuth login button:

@inject IOptionsMonitor<BaasOptions> Options;
@inject NavigationManager Navigation;

<MudButton OnClick="OnClickLogin" Variant="Variant.Text" Color="Color.Inherit">Login</MudButton>

@code {
    [CascadingParameter(Name = "HttpRequestState")]
    protected HttpRequestState? HttpRequestState { get; set; }

    public void OnClickLogin()
    {
        ArgumentNullException.ThrowIfNull(HttpRequestState);

        string currentPage = Navigation.ToBaseRelativePath(Navigation.Uri);
        string redirect = HttpRequestState.HostUri + $"/OAuthCallback?{Constants.QueryParams.OriginalPage}={currentPage}";

        QueryBuilder qb =
            new()
                {
                    // some query params for the request, omitted for brevity
                };

        Navigation.NavigateTo(new Uri(this.Options.CurrentValue.BaasUrlParsed, "/custom/thirdparty/auth") + qb.ToString());
    }
}


And it seems I get quite a few errors from the deployment:
Navigation failed when changing the location to https://baas.lukefz.xyz/custom/thirdparty/auth[...]
with an inner exception of
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()


I found a github issue with something similar which I now can't find again, but the root cause there was using Task.Result. However I am not using that anywhere so I'm not sure what is happening here, any suggestions would be appreciated
Was this page helpful?