aspnetcore
aspnetcore copied to clipboard
Blazor hot reloading not working with referenced assembly
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
I have two projects in a solution called Main and FeatureA. Main defines and configures the blazor app and references FeatureA and its _Imports file via .AddAdditionalAssemblies in Program.cs and AdditionalAssemblies in the Router component.
Hot reloading works for components defined in the Main module, but does not for components changed in the FeatureA project. I'm running using dotnet watch run --project Main.
Expected Behavior
Changes in the referenced FeatureA project should be updated with hot reload.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
8.0.102
Anything else?
.NET SDK: Version: 8.0.102 Commit: b7800db369 Workload version: 8.0.100-manifests.03fa9662
Runtime Environment:
OS Name: manjaro
OS Version:
OS Platform: Linux
RID: arch-x64
Base Path: /usr/share/dotnet/sdk/8.0.102/
.NET workloads installed: Workload version: 8.0.100-manifests.03fa9662 There are no installed workloads to display.
Host: Version: 8.0.2 Architecture: x64 Commit: 1381d5ebd2
.NET SDKs installed: 5.0.213 [/usr/share/dotnet/sdk] 6.0.202 [/usr/share/dotnet/sdk] 6.0.400 [/usr/share/dotnet/sdk] 6.0.403 [/usr/share/dotnet/sdk] 8.0.102 [/usr/share/dotnet/sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 5.0.16 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.4 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.16 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found: None
Environment variables: Not set
global.json file: Not found
Issue turned out to be the same as this. In short a .razor template was added to the AdditionalFiles item group in the project file, I don't know why, but I do think a more prominent warning would be nice, as mentioned in that issue too. It's currently very hard to figure out why hot reloading suddenly doesn't work if your IDE or another tool decides to add something redundant to AdditionalFiles.
Since I tested with a main blazor web project and an RCL I also found there's a difference between how those two are handled with the duplicated source file. In the RCL project hot reloading just stops work ("No hot reload changes to apply"), but in the Main web project the page crashed with some missing reference errors.
FWIW here is a repro: https://github.com/altschuler/HotReloadTest
Uncomment these two lines to trigger the problem: For the RCL: https://github.com/altschuler/HotReloadTest/blob/main/Lib/Lib.csproj#L10 For the main app: https://github.com/altschuler/HotReloadTest/blob/main/Main/Main.csproj#L10
I'll leave this open for someone to decide whether it needs more attention, but feel free to just close it.
Thanks!