Error: Circuit has been shut down due to error. on downloading file from Blazor Server

Viewed 1493

I created a webapp using Blazor Server. Part of the webapp is a file download as follows:

// called on button click, initiates the download
private async Task OnDownloadRequest(FileEntry file)
{
    NavManager.NavigateTo($"/download/{file.Id}", true);
}

// MVC controller
public class DownloadController
{
    [HttpGet("~/download/{downloadId}")]
    public async Task<IActionResult> Download([FromServices] MyContext dbContext, long downloadId, CancellationToken cancel)
    {
        File file = await dbContext.Files.FindAsync(downloadId);
        Stream stream = new MemoryStream(file.Content); 

        var result = new FileStreamResult(stream, "application/octet-stream")
        {
            FileDownloadName = file.Name,
            LastModified = file.LastModified
        };

        return result;
    }
}

// Startup.cs Configure method contains:
app.UseEndpoints(endpoints =>
{
    endpoints.MapBlazorHub();
    endpoints.MapControllerRoute("mvc", "{controller}/{action}");
    endpoints.MapFallbackToPage("/_Host");
});

Actually the download of the file works fine, but at the same time Blazor crashes with:

blazor.server.js:19 [2020-09-05T11:33:02.200Z] Error: Circuit has been shut down due to error.
e.log @ blazor.server.js:19
blazor.server.js:1 [2020-09-05T11:33:02.202Z] Information: Connection disconnected.

Anyone knows why blazor crashes in this case and how to fix it?

2 Answers

For more info, briefly note:

It appears so based on the behavior described here (disconnect on page refresh).

This issue should be resolved in .NET 5 RC2, which ships on October 13th. If you have the chance, please try that build to resolve your issue.

You can also try installing the nightly build of RC2 from https://github.com/dotnet/installer#installers-and-binaries and test that out.

We'll be backporting a fix for this to 3.1 in the next patch release.

Related