Open Jejuni opened 11 months ago
I came across this issue and wanted to share that I am experiencing a very similar problem in my Blazor wasm hosted application after migrating to .NET 8. Just like in the case described, I encounter an error stating that the assembly cannot be edited or changed due to the DOTNET_MODIFIABLE_ASSEMBLIES environment variable being set to '(null)', not 'Debug'.
I have tried setting DOTNET_MODIFIABLE_ASSEMBLIES to 'Debug' in various ways (including in Program.cs, through system environment variables, and via the command line), but the issue persists. My application's middleware configuration closely follows the recommended pattern, with app.UseAntiforgery() placed correctly between app.UseRouting() and app.UseEndpoints().
Any additional insights or solutions would be greatly appreciated, as this issue is impacting the efficiency of my development process.
My application's middleware configuration closely follows the recommended pattern, with app.UseAntiforgery() placed correctly between app.UseRouting() and app.UseEndpoints().
Any additional insights or solutions would be greatly appreciated, as this issue is impacting the efficiency of my development process.
@Solbstr, I would say if you are using the "minimal API approach" (the one with no Startup.cs, whether you have controllers or not does not matter) simply remove app.useRouting()
and app.UseEndpoints()
. Both are only required in very special cases where you need to change the order of middleware. As per the official routing documentation:
Apps typically don't need to call UseRouting or UseEndpoints. WebApplicationBuilder configures a middleware pipeline that wraps middleware added in Program.cs with UseRouting and UseEndpoints
If nothing else just try to remove UseRouting
. That fixed it for me
Thanks @Jejuni , seems that hot reload started working again after removal of app.useRouting().
To learn more about what this message means, what to expect next, and how this issue will be handled you can read our Triage Process document. We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. Because it's not immediately obvious what is causing this behavior, we would like to keep this around to collect more feedback, which can later help us determine how to handle this. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact work.
I have the same issue, but removing app.UseRouting()
causes my application to no longer render, giving this error in the browser console:
Error: One or more errors occurred. ('<' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.)
at Jn (marshal-to-js.ts:349:18)
at Ul (marshal-to-js.ts:306:28)
at 00b1e8b6:0x1faca
at 00b1e8b6:0x1bf8b
at 00b1e8b6:0xf172
at 00b1e8b6:0x1e7e4
at 00b1e8b6:0x1efda
at 00b1e8b6:0xcfec
at 00b1e8b6:0x440ad
at e.<computed> (cwraps.ts:338:24)
Do you guys have any suggestions other than removing app.UseRouting()
? 😄
We have the same issue as @NielsPilgaard. When we remove UseRouting it seems that all css/js-files gets the context of App.razor.
Working with frontend without hot-reload and close to no inspection support (children could not be evaluated on every semi-complex model) is getting very costly.
Surprised this fix is scheduled for .net9 :(
I managed to find a workaround, this very specific order of middleware allowed hot reload to work again, with UseRouting
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseAntiforgery();
So, it seems that app.UseBlazorFrameworkFiles();
, placed like mentioned above, makes Hot-reload work again. But this middleware is not supposed to be used in .net 8 as far as I understand (atleast the migration documentation states to remove that command).
Not sure if it adds any sort of regression or unwanted behaviour. Might be a quick-fix for local development, so thanks for the tip.
From my testing it's apparently enough to just place app.UseBlazorFrameworkFiles()
above app.UseStaticFiles()
.
// Other middleware like auth, swagger etc.
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.MapFallbackToFile("index.html");
app.Run();
Also ran in to this today, UseBlazorFrameworkFiles() fixes it but as said I thought this was not meant to be used anymore
Is there an existing issue for this?
Describe the bug
When using the
UseRouting
middleware as described in the migration documentation (the part about addingUseAntiforgery
right afterUseRouting
: https://learn.microsoft.com/en-us/aspnet/core/migration/70-80?view=aspnetcore-8.0&tabs=visual-studio#convert-a-hosted-blazor-webassembly-app-into-a-blazor-web-app) hot reload no longer works and fails with the error mentioned in the Exception sectionExpected Behavior
UseRouting
should continue to function when used with Blazor WebAppSteps To Reproduce
Repro Github: https://github.com/Jejuni/BlazorWebAppRoutingProblem
The repro is simply the default Blazor WebApp Wasm Global Template with
app.UseRouting();
added directly beforeUseAntiforgery
To produce the error start the app via F5, then make a simple change in
Home.razor
and try to hot reloadExceptions (if any)
The browser displays:
.NET Version
8.0.100
Anything else?
Asp.Net Core Version: 8.0.0 IDE: VS 17.8.1