Type 'Object' is defined in an assembly that is not referenced (NET Standard 2.0/.NET Framework 4.6.1) [duplicate]
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.
After installing NET Core 2.0 preview 2 and updating to the latest version of Visual Studio 2017 Preview (15.3), the references are now automatically installed.
According to this GitHub issue, dealing with a similar problem, you have to manually add a reference to the NETStandard.Library.NETFramework
package within your .NET Framework project for now*.
Either install it via NuGet Console:
Install-Package NETStandard.Library.NETFramework -Version 2.0.0-preview1-25305-02 -Pre
A few days ago, the NET Core/Standard 2.0 preview 2 was released, if you updated, the following version is needed:
Install-Package NETStandard.Library.NETFramework -Version 2.0.0-preview2-25405-01 -Pre
or via the NuGet store (check Show Pre-release versions) and search for NETStandard.Library.NETFramework
This will then resolve the references, the errors should vanish.
*Joperezr states that Microsoft is planning to let a tool handle this later.
For now you have to manually add a reference to this package which can be annoying, but in the future we are planning on the tooling doing this for you.
It's good to hear that for many people updates to Visual Studio resolved their issues; however, it is worth pointing out that it is no longer recommended to try to consume .NET Standard 2.0 libraries from .NET Framework 4.6.1 projects because of bugs and other issues. You should use 4.7.2 or newer instead, where possible.
Immo Landwerth, Program Manager on the .NET team at Microsoft, tweeted:
Sorry but we messed up. We tried to make .NET Framework 4.6.1 retroactively implement .NET Standard 2.0. This was a mistake as we don't have a time machine and there is a tail of bugs.
If you want to consume .NET Standard 1.5+ from .NET Framework, I recommend to be on 4.7.2.
The .NET Standard comparability matrix has been updated with a footnote for 4.6.1 which reads:
The versions listed here represent the rules that NuGet uses to determine whether a given .NET Standard library is applicable. While NuGet considers .NET Framework 4.6.1 as supporting .NET Standard 1.5 through 2.0, there are several issues with consuming .NET Standard libraries that were built for those versions from .NET Framework 4.6.1 projects. For .NET Framework projects that need to use such libraries, we recommend that you upgrade the project to target .NET Framework 4.7.2 or higher.