Type 'Object' is defined in an assembly that is not referenced (NET Standard 2.0/.NET Framework 4.6.1)

jAC picture jAC · Jun 20, 2017 · Viewed 48.1k times · Source

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.

Net Standard Implementation by Net Framework and Core

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?

Answer

OMID picture OMID · Sep 17, 2018

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>