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 badges1 Answer
Reset to default 0To 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");
}
}