-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Describe the bug
Create a Controller for sending downloads to the client as follows. Call it using the Navigation Manager and notice that this can only be done once. On the second attempt Blazor crashes. This only happens with NET 5 Preview 8, everything is permanently fine when doing this with NET Core 3.1.
To Reproduce
Configure method in Startup.cs:
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapControllerRoute("mvc", "{controller}/{action}"); // added this line
endpoints.MapFallbackToPage("/_Host");
});
DownloadController:
public class DownloadController : ControllerBase
{
[HttpGet("~/download/{downloadId}")]
public async Task<IActionResult> Download(long downloadId)
{
var buffer = Encoding.UTF8.GetBytes("Hello! Content is here.");
var stream = new MemoryStream(buffer);
var result = new FileStreamResult(stream, "text/plain");
result.FileDownloadName = "test.txt";
return result;
}
}
Add some code in Index.razor to test it:
<button type="button" class="btn btn-sm btn-primary" @onclick="@(() => Download())">
Downloadtest
</button>
@code {
[Inject]
NavigationManager NavManager { get; set; }
private async Task Download()
{
NavManager.NavigateTo("/download/1", true);
}
}
Now run the project, on the Index page click the download button twice.
On first click, everything works fine. Second click leads to
blazor.server.js:19 [2020-09-05T15:26:19.311Z] Error: Circuit has been shut down due to error.
e.log @ blazor.server.js:19
blazor.server.js:1 [2020-09-05T15:26:19.317Z] Information: Connection disconnected.
Note that this only happens when using NET 5 Preview 8. With NET Core 3.1 and the same code, it works permanently fine.
Sample with NET Core 3.1:
https://github.com/wondering639/DownloadTest
Just run it, hit the Downloadtest button multiple times, everything works fine.
Sample with NET 5 Preview 8:
https://github.com/wondering639/DownloadTestDotNet5
Just run it, hit the Downloadtest button twice, on second click the described error occurs.
Exceptions (if any)
No exception, only error in the browser console (Chrome) as already mentioned above:
blazor.server.js:19 [2020-09-05T15:26:19.311Z] Error: Circuit has been shut down due to error.
e.log @ blazor.server.js:19
blazor.server.js:1 [2020-09-05T15:26:19.317Z] Information: Connection disconnected.
Further technical details
-
ASP.NET Core version
.NET 5 Preview 8 -
Include the output of
dotnet --info
C:\Users\myuser>dotnet --info
.NET Core SDK (gemäß "global.json"):
Version: 5.0.100-preview.8.20417.9
Commit: fc62663a35
Laufzeitumgebung:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100-preview.8.20417.9\
Host (useful for support):
Version: 5.0.0-preview.8.20407.11
Commit: bf456654f9
.NET SDKs installed:
2.1.802 [C:\Program Files\dotnet\sdk]
3.1.101 [C:\Program Files\dotnet\sdk]
3.1.301 [C:\Program Files\dotnet\sdk]
3.1.401 [C:\Program Files\dotnet\sdk]
5.0.100-preview.8.20417.9 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0-preview.8.20414.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0-preview.8.20407.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0-preview.8.20411.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
- The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version
Microsoft Visual Studio Community 2019 Preview
Version 16.8.0 Preview 2.1
Please let me know if there is any workaround for it / how I can send file downloads from Blazor Server when using NET Core 5 Preview 8, thanks!