Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotnet Watch Run indefinitely reloads #39073

Closed
jamesikanos opened this issue Dec 14, 2021 · 21 comments
Closed

Dotnet Watch Run indefinitely reloads #39073

jamesikanos opened this issue Dec 14, 2021 · 21 comments
Assignees
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) feature-hot-reload This issue is related to the Hot Reload feaature investigate
Milestone

Comments

@jamesikanos
Copy link

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

@pranavkm pranavkm transferred this issue from dotnet/sdk Dec 16, 2021
@mkArtakMSFT mkArtakMSFT added area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) investigate feature-hot-reload This issue is related to the Hot Reload feaature labels Dec 16, 2021
@mkArtakMSFT mkArtakMSFT added this to the 6.0.x milestone Dec 16, 2021
@mrlife
Copy link
Contributor

mrlife commented Dec 17, 2021

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.

@chris-metz
Copy link

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

@rgwood
Copy link

rgwood commented Feb 14, 2022

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.

@mrlife
Copy link
Contributor

mrlife commented Feb 14, 2022

Just curious, is this an issue for everyone or is there something specific about our projects that are causing it? If the former, I would expect a lot more activity in this issue... unless there are not a lot of people using hot reload.

@jamesikanos
Copy link
Author

In my experience, this only affects Console projects. Works as expected in Web Projects.

Maybe there aren't many people doing dotnet watch run for Console projects?

@mrlife
Copy link
Contributor

mrlife commented Feb 15, 2022

I am running a Blazor project fwiw.

@jamesikanos
Copy link
Author

Previous comment rescinded @mrlife . Consider it done.

@mrlife
Copy link
Contributor

mrlife commented Feb 18, 2022

@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

@mrlife
Copy link
Contributor

mrlife commented Apr 5, 2022

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

@CommonLoon102
Copy link

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.
dotnet/razor#7626

@Mike-E-angelo
Copy link

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

@mkArtakMSFT mkArtakMSFT assigned javiercn and unassigned pranavkm May 18, 2022
@javiercn
Copy link
Member

@jamesikanos I can't reproduce this behavior with the 6.0.300 SDK. Are you still having issues?

@javiercn
Copy link
Member

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.

@mrlife are you still running into this problem with 6.0.300? If so, could you please file a separate issue with concrete details (a repro if possible) so that we can look at it?

@javiercn
Copy link
Member

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

Hot reload should work with Blazor Server

@javiercn
Copy link
Member

javiercn commented May 19, 2022

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

@mrlife If you do dotnet watch --verbose

You will see that the issue is the process is failing to start:

An error occurred trying to start process 'C:\work\scratch\blazorserverwatch\bin\Debug\net6.0\blazorserverwatch' with working directory 'C:\work\scratch\blazorserverwatch'. The specified executable is not a valid application for this OS platform.

And that's why there is a loop.

@javiercn
Copy link
Member

@rgwood In your case the issue with your project is the TFM. It needs to be net6.0 not netcoreapp6.0

@javiercn
Copy link
Member

In general for folks running into this issue, stop dotnet watch and try to build the app with dotnet build or run it with dotnet run and if that fails, it's likely the issue to start with.

@javiercn
Copy link
Member

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

@mrlife
Copy link
Contributor

mrlife commented May 20, 2022

@mrlife are you still running into this problem with 6.0.300? If so, could you please file a separate issue with concrete details (a repro if possible) so that we can look at it?

@mrlife If you do dotnet watch --verbose

You will see that the issue is the process is failing to start:

An error occurred trying to start process 'C:\work\scratch\blazorserverwatch\bin\Debug\net6.0\blazorserverwatch' with working directory 'C:\work\scratch\blazorserverwatch'. The specified executable is not a valid application for this OS platform.

And that's why there is a loop.

Hi @javiercn, thank you for checking it out. Here is the new issue: #41776

@rgwood
Copy link

rgwood commented May 22, 2022

Thanks @javiercn. Attempted to confirm the fix but it seems like I'm stuck on v6.0.105 until a newer SDK is published for Linux (on Fedora 36, installing via dnf install dotnet-sdk-6.0 or dotnet-install.sh gets v6.0.105).

@javiercn
Copy link
Member

@rgwood It'll take some time until the fix is available. I proposed patching it, but it didn't make it into this month patch, so we are looking at July-ish for it to be released.

If you want to verify the fix, you could clone the SDK repo. Run build.sh at the root and then eng\dogfood.sh

That will setup the terminal with a local copy of the dotnet-sdk (including the fix) that contains a dotnet-watch version you can use against your project for validation.

In general, my suggestion would be to try and run dotnet build and dotnet run to see if those run without issue.

@mkArtakMSFT mkArtakMSFT modified the milestones: 6.0.x, 6.0.5 May 23, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) feature-hot-reload This issue is related to the Hot Reload feaature investigate
Projects
None yet
Development

No branches or pull requests

9 participants