Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 452
jAC Avatar asked Jun 20 '17 11:06

jAC


People also ask

Is defined in assembly that is not referenced?

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.

What are .NET reference assemblies?

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.


2 Answers

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> 
like image 144
OMID Avatar answered Sep 26 '22 03:09

OMID


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.

like image 24
FerX32 Avatar answered Sep 24 '22 03:09

FerX32