Skip to content

Hot reload crash when add new file to wwwroot #67052

@keatkeat87

Description

@keatkeat87

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

when dotnet watch run
Adding a file to wwwroot will crash hot reload.
Please check Steps To Reproduce for details.

Expected Behavior

hot reload no crash

Steps To Reproduce

https://github.com/keatkeat87/aspnet-core-hot-reload-issue.git

dotnet new webapp -o TestHotReload
dotnet watch run --verbose
Create a file in wwwroot
Set-Content -Path ".\wwwroot\test.txt" -Value "hello"

Error:

dotnet watch ⌚ File added: .\wwwroot\test.txt
dotnet watch ⌚ Terminating remaining child processes.
dotnet watch ⌚ [TestHotReload (net10.0)] Terminating process 13256 (Ctrl+C).
info: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...
dotnet watch ⌚ [TestHotReload (net10.0)] Waiting for process 13256 to exit within 5s.
dotnet watch ⌚ [TestHotReload (net10.0)] Process id 13256 ran for 139541ms and exited with exit code 0.
dotnet watch ⌚ [TestHotReload (net10.0)] Exited
dotnet watch 🔥 [TestHotReload (net10.0)] Disposing agent communication pipe
dotnet watch 🌐 [Browser #1] Disconnected.
dotnet watch ❌ An unexpected error occurred: System.InvalidOperationException: Unexpected true - file HotReloadMSBuildWorkspace.cs line 158
   at Microsoft.CodeAnalysis.Contract.Fail(String message, Int32 lineNumber, String filePath)
   at Microsoft.CodeAnalysis.ExternalAccess.HotReload.Api.HotReloadMSBuildWorkspace.UpdateFileContentAsync(IEnumerable`1 changedFiles, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watch.CompilationHandler.UpdateFileContentAsync(IReadOnlyList`1 changedFiles, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.<>c__DisplayClass13_3.<<WatchAsync>g__CaptureChangedFilesSnapshot|8>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watch.Program.RunAsync()

Remark:
Edit file content is ok.
Adding a file to outside wwwroot is ok.
Delete file inside wwwroot is ok.

.NET Version

10.0.300

Anything else?

.NET SDK:
Version: 10.0.300
Commit: caa81fa497
Workload version: 10.0.300-manifests.e0989437
MSBuild version: 18.6.3+caa81fa49

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26200
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.300\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.8
Architecture: x64
Commit: 94ea82652c

.NET SDKs installed:
10.0.108 [C:\Program Files\dotnet\sdk]
10.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-commandlinetoolsIncludes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPIfeature-hot-reloadThis issue is related to the Hot Reload feaature

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions