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?