sdk: dotnet watch on net6.0 project results in FileNotFoundException for SystemRuntime
Description
When running the dotnet watch from .net 7 on a net6.0 project, a FileNotFoundException is thrown claiming that System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a could not be found. net7.0 and net5.0 projects work fine.
Reproduction Steps
dotnet new console -f net6.0
dotnet watch run
Expected behavior
The program should output Hello, World!.
Actual behavior
dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload.
💡 Press "Ctrl + R" to restart.
dotnet watch 🔧 Building...
Determining projects to restore...
All projects are up-to-date for restore.
watchtest -> D:\Test\watchtest\bin\Debug\net6.0\watchtest.dll
dotnet watch 🚀 Started
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.Reflection.RuntimeAssembly.GetType(QCallAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive, ObjectHandleOnStack assemblyLoadContext)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at System.Reflection.Assembly.GetType(String name, Boolean throwOnError)
at System.StartupHookProvider.CallStartupHook(StartupHookNameOrPath startupHook)
at System.StartupHookProvider.ProcessStartupHooks()
dotnet watch ❌ Exited with error code -532462766
dotnet watch ⏳ Waiting for a file to change before restarting dotnet...
Regression?
This is a regression from SDK 7.0.100-rc.2
Known Workarounds
This can be worked around by creating a global.json file and pointing it to the v6 SDK (thanks @nicholashead)
{
"sdk": {
"version": "6.0.403"
}
}
Alternatively, adding any argument after dotnet watch run will work. e.g.
dotnet watch run bogus
(thanks @akorchev)
Configuration
.NET SDK: Version: 7.0.100 Commit: e12b7af219
Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.100\
Host: Version: 7.0.0 Architecture: x64 Commit: d099f075e4
Other information
It’s possible that my installation is corrupted. However I have uninstalled and reinstalled several times
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 34
- Comments: 28 (1 by maintainers)
I’ve hit this too and discovered this issue. Strangely enough putting anything after “run” seems to fix the problem (even without global.json) e.g.
dotnet watch run bogus. Found it by dumb luck after a typo.Yes, this is exactly when it started happening for me. I was not running any betas or anything.
Would be interested to know if anyone got this recently after updating Visual Studio 2022/.NET Core 7.
I’m experiencing this as well. I worked around it for now by creating a global.json file and pointing it at the v6 SDK:
Same here
Same here.
Yesterday, After upload to VS 17.4.0, i have the same error. and I just reinstalled .net 6 and everything works.
Happening to me after updating my VS 2022 from 17.7.x to 17.8.
.NET SDK 8 is used now by default. And the project is targeted net5.0. But everything else is totally the same as described here before.
dotnet run works fine while dotnet watch run does not.
Adding an arbitrary word to the command does not help.
global.json helps.
I would like this issue eventually fixed. Project targeting is planned to switch to net6.0 soon. But switching to .NET 8 is not in the priority now.
@VictorMalcov it should work for the “dotnet” command line. Are you getting an error message or something else?
This did not work for me.