question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet watch on net6.0 project results in FileNotFoundException for SystemRuntime

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:34
  • Comments:22

github_iconTop GitHub Comments

27reactions
akorchevcommented, Nov 9, 2022

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.

5reactions
nicholasheadcommented, Nov 16, 2022

Would be interested to know if anyone got this recently after updating Visual Studio 2022/.NET Core 7.

Yes, this is exactly when it started happening for me. I was not running any betas or anything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installing .net-core 7 stops `dotnet watch run` working on . ...
After that, when I use dotnet watch run I get a strange error: Unhandled exception. System.IO.FileNotFoundException: Could not load file or ...
Read more >
System.IO.FileNotFoundException: 'Could not load file or ...
I have an application in .net core. the application was running fine, but the error started coming after I installed.
Read more >
dotnet watch command - .NET CLI
The dotnet watch command is a file watcher that runs a dotnet command when changes in source code are detected.
Read more >
NET Foundation
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, ...
Read more >
NET core(.NET6) System.IO.FileLoadException : Could not ...
currently i am running tests using Automation project(C++ project) and it was using .NET Framework 3.5 TestAPP.dll to run the tests,.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found