c# – Cannot load file or assembly after upgrade to .NET 8.0


I have a Class Library project targeting .NET Framework 4.8. I used the .NET Upgrade Assistant extension in Visual Studio to upgrade it to target .NET 8.0. After fixing a number of errors that resulted from this change, I’m left with a single persistent error:

‘Could not load file or assembly ‘System.Runtime, Version=4.2.2.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its
dependencies. Reference assemblies should not be loaded for execution.
They can only be loaded in the Reflection-only loader context.
(Exception from HRESULT: 0x80131058)’

I’ve tried resolutions in the answers to this question such as deleting bin/obj files and rebuilding, as well as clearing out dependent assembly entries in App.config. I tried installing the System.Runtime nuget package (though, I would think that’s installed by default?) and this did not change the error. This answer suggested installing System.ServiceModel.Primitives, but that also did not change anything.

I’m at a bit of a loss. I’m not sure what else I can do to resolve this error. Further, I’m not really sure what the error is trying to tell me. Any guidance on that would be appreciated!

Leave a Reply

Your email address will not be published. Required fields are marked *