Home > Net >  Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.R
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.R

Time:11-10

After installing .Net 7, when I use dotnet watch I get this error:

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()

I can successfully build and run the project using Visual Studio, but can't use dotnet cli. How can this error be fixed?

CodePudding user response:

After changing the target framework of my project, now I can use dotnet watch run. Could it be solved in another way, I don't know.

enter image description here


As a workaround, global.json below may help: select the .NET version to use

On rare occasions, you may need to use an earlier version of the SDK. You specify that version in a global.json file. The "use latest" policy means you only use global.json to specify a .NET SDK version earlier than the latest installed version.

Create a global.json file and point it to the v6 SDK. global.json can be placed anywhere in the project file hierarchy.

{
    "sdk": {
        "version": "6.0.403"
    }
}

CodePudding user response:

For me, the solution was to add a global.json to the root of your project. With the SDK version, you want to use.

{ "sdk": { "version": "6.0.403" } }

For me 6.0.403 that forces dotnet watch to use this version.

  • Related