I'm using the .NET Standard 2.0 preview, on which my Class Libraries are based.
After having trouble with a few NuGet packages, especially regarding archive extraction, I decided to migrate my .NET Core 2.0 Console projects back to the .NET Framework 4.6.1.
The .NET Framework 4.6.1 is supposed to implement the .NET Standard 2.0 specification - according to different sources. Especially the dotnet/standard GitHub Repo.
Unfortunately, the migration to the .NET Framework resulted in the following errrors throughout all of .NET Framework Console projects:
Error CS0012 The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
Where Object
can be anything: Enum
, Task
, ...
How would I reference .NET Standard 2.0 class libraries with .NET Framework (4.6.1) without getting such errors?
When you get this error, it means that code you are using makes a reference to a type that is in an assembly, but the assembly is not part of your project so it can't use it.
Reference assemblies are usually distributed with the Software Development Kit (SDK) of a particular platform or library. Using a reference assembly enables developers to build programs that target a specific library version without having the full implementation assembly for that version.
Try to add a reference to netstandard in web.config as below:
<system.web> <compilation debug="true" targetFramework="4.7.1"> <assemblies> <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/> </assemblies> </compilation> </system.web>
I had this problem even after using the latest 2.0, and VS 15.3. However, I think my problem was different. After upgrading from Core 1.1, to 2.0, for some reason, my .web's .csproj had <RuntimeFrameworkVersion>1.1.2</RuntimeFrameworkVersion>
. Which prevented the project from targeting the correct 2.0 version.
My class libraries (.Layer) projects had <NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
.
I deleted both of them and my project finally started using 2.0 and everything went fine after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With