Search code examples
c#.netvisual-studioupgrade.net-8.0

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!


Solution

  • I was able to resolve this issue.

    The problem was actually being caused by an outdated license file being used by one of my packages (ActiveReports). Deleting the invalid license file caused it to be regenerated, which fixed the error I was experiencing.