最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

TaskCanceledException raised by RemoteNavigationManager in Blazor Server app - Stack Overflow

programmeradmin4浏览0评论

I have a Blazor Server app which creates a zip file in memory and delivers that zip file via an call to a get method of an controller. I use following call inside of a button to start the download:

navigationManager.NavigateTo($"api/DownloadFile?RequestGuid={WebUtility.UrlEncode(RequestGuid.ToString())}", true);

Everything works fine, but 1 or 2 minutes after the successfull download the application crashs with following error:

Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager[4] Navigation failed when changing the location to api/DownloadFile?RequestGuid=db296363-ec46-4661-a8f5-78f9537114bc 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.<g__PerformNavigationAsync|0>d.MoveNext()

Is there any workaround on how to avoid this issue?

I have a Blazor Server app which creates a zip file in memory and delivers that zip file via an call to a get method of an controller. I use following call inside of a button to start the download:

navigationManager.NavigateTo($"api/DownloadFile?RequestGuid={WebUtility.UrlEncode(RequestGuid.ToString())}", true);

Everything works fine, but 1 or 2 minutes after the successfull download the application crashs with following error:

Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager[4] Navigation failed when changing the location to api/DownloadFile?RequestGuid=db296363-ec46-4661-a8f5-78f9537114bc 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.<g__PerformNavigationAsync|0>d.MoveNext()

Is there any workaround on how to avoid this issue?

Share Improve this question edited Feb 17 at 6:43 Qiang Fu 8,6061 gold badge6 silver badges16 bronze badges asked Feb 14 at 19:08 StefStef 738 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

To avoid the issue, you could try use JS Interop to download the file instead of navigation.

@inject IJSRuntime JS

@code {
    private async Task TriggerDownload(Guid requestGuid)
    {
        var url = $"api/DownloadFile?RequestGuid={WebUtility.UrlEncode(requestGuid.ToString())}";
        await JS.InvokeVoidAsync("window.open", url, "_blank");
    }
}
发布评论

评论列表(0)

  1. 暂无评论