aspnetcore: Dotnet Watch Run indefinitely reloads

Describe the bug

Calling dotnet watch run will detect changes continuously and loop forever.

The first time a file is changed, the Program will rebuild and run. But, after that it will continuously rebuild and reload, even without changing the file.

Workaround, run dotnet watch run --no-hot-reload and it will behave as desired (ie: only reloading when a file actually changes).

Environment: WSL2

To Reproduce

  1. dotnet new console
  2. dotnet watch run
  3. Save “Program.cs”

Observe that the program will constantly restart.

watch : Started
watch : Exited
watch : Waiting for a file to change before restarting dotnet...
watch : Building...
  UnregisteredDeviceSearch -> /home/jamesikanos/scratch/UnregisteredDeviceSearch/bin/Debug/net6.0/UnregisteredDeviceSearch.dll
watch : Started
watch : Exited
watch : Waiting for a file to change before restarting dotnet...
watch : Building...
  UnregisteredDeviceSearch -> /home/jamesikanos/scratch/UnregisteredDeviceSearch/bin/Debug/net6.0/UnregisteredDeviceSearch.dll
watch : Started
watch : Exited

Exceptions (if any)

No exception

Further technical details

Running on VSCode. This behaviour is also observed when running dotnet watch run from Ubuntu terminal.

.NET SDK (reflecting any global.json): Version: 6.0.100 Commit: 9e8b04bbff

Runtime Environment: OS Name: ubuntu OS Version: 20.04 OS Platform: Linux RID: ubuntu.20.04-x64 Base Path: /usr/share/dotnet/sdk/6.0.100/

Host (useful for support): Version: 6.0.0 Commit: 4822e3c3aa

.NET SDKs installed: 2.1.816 [/usr/share/dotnet/sdk] 3.1.410 [/usr/share/dotnet/sdk] 6.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.28 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.28 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.16 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.28 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.16 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 21 (14 by maintainers)

Most upvoted comments

I’m seeing the same thing for dotnet watch.

% dotnet watch
watch : Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload. Press "Ctrl + R" to restart.
watch : Building...
  Determining projects to restore...
  All projects are up-to-date for restore.
  MyProject -> /Users/username/projects/MyProject/bin/Debug/net6.0/MyProject.dll
watch : Started
watch : Building...
  MyProject -> /Users/username/projects/MyProject/bin/Debug/net6.0/MyProject.dll
watch : Started
watch : Building...
  MyProject -> /Users/username/projects/MyProject/bin/Debug/net6.0/MyProject.dll
watch : Started
watch : Building...

Note that I am on macOS 12.0.1 with dotnet 6.0.1.

Reproduced in a repl.it notebook: https://replit.com/@ripley/DotnetWatchRepro#README.md

This seems like a pretty big bug in dotnet watch and I hope it can get addressed.

I correct myself. netcoreapp6.0 works, but the issue is with <StartupObject>Program</StartupObject> and top level statements. As far as I can tell this is already addressed in 6.0.300

45 seconds… if you’re lucky @CommonLoon102. 😛 I still have yet to see this feature work well or at all in my environment.

Could someone comment whether hot reload is supposed to work in a Blazor Server app?

It does work but it takes 45 seconds to complete though. https://github.com/dotnet/razor-tooling/issues/7626

Could someone comment whether hot reload is supposed to work in a Blazor Server app?

@pranavkm @mkArtakMSFT

I can reproduce this by adding one line to a fresh Blazor Server project.

  1. Create a new Blazor Server project (I am on macOS)
  2. Add the following line to the csproj: <DefaultAppHostRuntimeIdentifier>win-x64</DefaultAppHostRuntimeIdentifier>
  3. Run ‘dotnet watch’ or ‘dotnet watch run’ in terminal to see the issue

Can confirm the same issue here (Windows 11, dotnet 6.0.101)