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.
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.
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.
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
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!
Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
Same issue here, doing the same thing. However it works perfectly local but in Azure it gives the same error message.
message: Error: Circuit has been shut down due to error.
using this docker image (ASP.NET CORE 3.1) as base:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
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?
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.
Having same issue on .NET Core 3.1
From comparing an environment that is running older .NET Core 3.1 runtimes to one that has the latest, the issue seems to be in "blazor.server.js", and as far as I can tell, the following push https://github.com/dotnet/aspnetcore/pull/23224 is why this issue started happening.
Curious as to how this one slipped past QA to be honest...
Yeah this is impacting us in production right now. Any idea of when this might be addressed? No files can be downloaded without the user needing to refresh the page due to an uncaught error.
@chassq, I don't work for Microsoft, so don't quote me on this, but judging by https://github.com/dotnet/aspnetcore/issues/25724 the issue has been fixed with this pull https://github.com/dotnet/aspnetcore/pull/26297 and I'm assuming will hopefully appear on the next minor update on the .NET Core runtimes.
This version: .NET Core 3.1.8 has release notes that indicate it contains: Disconnect circuit on beforeunload event and fix display #24592.
This is fixed in: Revert "Disconnect circuit on 'beforeunload' event" #26297 that is part of Milestone 5.0.0-rc2 that we are waiting to be released…
Would it be possible to uninstall .NET Core 3.1.8 and install the previous version: .NET Core 3.1.7 and see if that fixes it for now?
@captainsafia @pranavkm This is fixed now, right? Can we close it, or are we keeping it open until some patch release goes out?
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.
@captainsafia
Is the fixed version of dotnet-Core already released?
Maybe you could say the exact Versionnumber. I am currently on 3.1.403.15556... is it the fixed one?
Thanks for your help!
@JoeGER94 is a current workaround you can use this if it's just for PDFs.
https://medium.com/@benjaminvertonghen/printing-pdfs-in-blazor-8dff559101f9
@JoeGER94 It was fixed in RC2. It will be backported in the next release of 3.1.
Hi there, I get the same error not when using the navigation manager but when using href of html tag redirecting to Azure AD B2C (https://mysitename.org/AzureADB2C/Account/SignIn).
blazor.server.js:19 [2020-10-27T10:54:02.115Z] Error: Circuit has been shut down due to error.
e.log @ blazor.server.js:19
Environment:
C:\Users\JunaidB>dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.403
Commit: 9e895200cd
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.403\
Host (useful for support):
Version: 3.1.9
Commit: 774fc3d6a9
.NET Core SDKs installed:
3.1.301 [C:\Program Files\dotnet\sdk]
3.1.403 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Hi there, I get the same error not when using the navigation manager but when using href of html tag redirecting to Azure AD B2C (https://mysitename.org/AzureADB2C/Account/SignIn).
@j-bedford - I got the same error too, but it was resolved by opening up my project in Visual Studio Preview, going into Properties and changing it to .Net Core 5. See: https://github.com/ADefWebserver/BlazorSimpleSurvey/
Hi there, I get the same error not when using the navigation manager but when using href of html tag redirecting to Azure AD B2C (https://mysitename.org/AzureADB2C/Account/SignIn).
@j-bedford - I got the same error too, but it was resolved by opening up my project in Visual Studio Preview, going into Properties and changing it to .Net Core 5. See: https://github.com/ADefWebserver/BlazorSimpleSurvey/
Thanks for your response. The app is in production at the moment so I cannot upgrade it to .NET 5 yet. I will have to wait for the fix which I believe will be released in November.
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...
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!
@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...
I have tried doing this and am still experiencing the same problem in production, but not when running locally. I am currently running Visual Studio 2019 16.8.0 (Preview 6.0) with .NET 5 RC2 installed. As mentioned, when I run the application locally I don't experience these issues, however I am experiencing them when I publish as self-contained to an Azure App Service.
For now, my workaround is to use JSInterop to open a new tab to the link that downloads the file (my app allows for data to be exported to CSV). I'm still experiencing the issue when a user tries to navigate to the Logout page which uses Azure AD B2C, similar to what @j-bedford is experiencing.
I have the app available to the public if anyone wants to take a look: https://whovisitedandwhen.com
I have tried doing this and am still experiencing the same problem in production
@jberlyn - Darn so sorry that is not working for you :(
I'm still experiencing the issue when a user tries to navigate to the Logout page which uses Azure AD B2C, similar to what @j-bedford is experiencing.
@jberlyn - I don't know if this will help, but, to handle logout, I upgraded to Microsoft.Identity.Web.UI and implemented a Areas/MicrosoftIdentity/Pages/Account/SignedOut.cshtml page.
Most helpful comment
@JoeGER94 It was fixed in RC2. It will be backported in the next release of 3.1.