错误:电路因错误而关闭。从 Blazor 服务器下载文件

ste*_*wpf 6 download asp.net-core blazor-server-side

我使用 Blazor 服务器创建了一个 web 应用程序。webapp的一部分是文件下载,如下:

// 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");
});
Run Code Online (Sandbox Code Playgroud)

实际上文件的下载工作正常,但与此同时 Blazor 崩溃了:

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.
Run Code Online (Sandbox Code Playgroud)

任何人都知道为什么 blazor 在这种情况下崩溃以及如何修复它?

ste*_*wpf 0

问题仅出现在 NET 5 Preview 8 中,而不会出现在 NET Core 3.1 中。错误报告提交于https://github.com/dotnet/aspnetcore/issues/25646

  • 我使用.NET Core 3.1,但错误仍然存​​在! (2认同)