aspnetcore: Blazor Server with MVC Controller for downloads leads to "Error: Circuit has been shut down due to error." in blazor.server.js:19

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!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (7 by maintainers)

Most upvoted comments

@JoeGER94 It was fixed in RC2. It will be backported in the next release of 3.1.

Thanks for your response. The app is in production at the moment so I cannot upgrade it to .NET 5 yet.

@j-bedford - I too have my app in production. I am hosted on Azure and was able to deploy it using ‘self-contained’ where the .Net 5 runtime is deployed with the app. Just an option…

Ah I see. Thanks for that suggestion!

Yep! This is the exact issue we resolved and added a test case to cover. As mentioned above, it’ll ship in RC2 and will be backported into the next 3.1 release.

I’m having this exact problem too on ASP.NET Core 3.1 deployed as a standalone build to a 2008 R2 server. It works fine on my laptop but on the server it fails. No exception in the browser console, nothing on the system console, nothing in the Event Log, even my middleware isn’t picking up anything and it’s configured to catch any unhandled exceptions. Seems like the NavigationManager.NavigateTo method breaks the circuit if forceReload is set to true. Could this be a problem with a recent update to .NET Core 3.1?

Scratch that - I have been able to reproduce it on my laptop as well. I am on 3.1.402 with runtime 3.1.8 (and various other prior versions). I am 100% certain this was working fine about a week ago, and it’s definitely an issue calling NavigationManager.NavigateTo(“url/goes/here”, true);

My only workaround at this point is to invoke some javascript to open the url in a new tab. This really needs to be fixed; downloading a file is a rather fundamental part of most websites.