Could not load file or assembly 'netstandard' from FW 4.8 console app

114 views Asked by At

I have an older console app that targets .NET Framework 4.8. It loads a few Nugets that all support .NET Standard 2.0 as well as 2.1. The console app builds just fine but I get this runtime error as the first Nuget DLLs gets loaded:

System.IO.FileNotFoundException: Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
File name: 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ---> System.IO.FileNotFoundException: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
File name: 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

So, compatibility-wise Framework 4.8 should be fine with .NET Standard 2.0. Is there a good reason why the runtime cannot load netstandard 2.0 or 2.1?

[EDIT] Screenshot from the console app's implicit dependencies enter image description here

2

There are 2 answers

3
PMF On

.Netstandard 2.1 requires .NET 5.0+. It is not supported by .NET Framework 4.8. Looks like you are trying to load an assembly that targets netstandard 2.1 only (maybe one of your nugets doesn't support 2.0, or when it has multiple targets, the wrong one is choosen for some reason).

0
Jonas Rembratt On

Ok, so problem was simply how the project was scaffolded, with assembly unification and upgrade in the App.config file. The default was, apparently, to always upgrade netstandard to 2.1, which doesn't work with framework 4.8. Not sure if this is a bug in the Rider project template or if VS also does this. By simply commenting out the assembly upgrade directive the problem got resolved.

enter image description here

Also: https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions

[EDIT]: Moving forward, it seems the App.config file gets rewritten every time I change the project setup, like changing project references or adding/removing a Nuget package. I had forgot how messy old framework project really was.