dotnet watch on net6.0 project results in FileNotFoundException for SystemRuntime
See original GitHub issueDescription
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
Issue Analytics
- State:
- Created 10 months ago
- Reactions:34
- Comments:22
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.