You must add a reference to assembly 'netstandard, Version=2.0.0.0

asp.net.Netasp.net Mvc.Net Framework-Version

asp.net Problem Overview


The project is an ASP.NET MVC Web App targeting the .NET Framework 4.6.1.

All of a sudden (some NuGet packages were upgraded) I started to get the following error during runtime:

> CS0012: The type 'System.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'.

In my main view Index.cshtml, in a line where I make use of @Html.ActionLink

I do have .NET Core SDK 2.0 and .NET Framework 4.7.1 installed in my machine but I don't want to include a reference to it. This is a .NET Framework web app only, it's hosted on Windows IIS where the installed framework is 4.6.1, there's no NET Core installed in the server.

So why is it asking to add a reference to netstandard? How can I fix it without referencing netstandard but the full Windows .NET Framework 4.6.1?

I've checked out a previous commit which worked fine and I'm still getting this error. So it's not related to NuGet packages being upgraded. Seems to be something on my local dev machine.

If a publish the app to a directory and run it with IIS it works.

Link to .csproj gist

packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.5.0.2" targetFramework="net46" />
  <package id="BundleTransformer.Core" version="1.9.69" targetFramework="net46" />
  <package id="BundleTransformer.Handlebars" version="1.9.73" targetFramework="net46" />
  <package id="BundleTransformer.Less" version="1.9.69" targetFramework="net46" />
  <package id="BundleTransformer.Yui" version="1.9.52" targetFramework="net46" />
  <package id="Dapper" version="1.42" targetFramework="net46" />
  <package id="EcmaScript.Net" version="1.0.1.0" targetFramework="net46" />
  <package id="EntityFramework" version="6.0.0" targetFramework="net46" />
  <package id="Glimpse" version="1.8.6" targetFramework="net46" />
  <package id="Glimpse.AspNet" version="1.9.2" targetFramework="net46" />
  <package id="Glimpse.Mvc5" version="1.5.3" targetFramework="net46" />
  <package id="JavaScriptEngineSwitcher.Core" version="1.2.4" targetFramework="net46" />
  <package id="JavaScriptEngineSwitcher.V8" version="1.3.0" targetFramework="net46" />
  <package id="jQuery" version="2.1.3" targetFramework="net46" />
  <package id="jQuery.Validation" version="1.13.1" targetFramework="net46" />
  <package id="LowercaseDashedRoute" version="1.0.14" targetFramework="net46" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net46" />
  <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net46" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net46" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net46" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net46" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net46" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net46" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net46" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net46" />
  <package id="Microsoft.Owin" version="3.0.1" targetFramework="net46" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net46" />
  <package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net46" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
  <package id="Moment.js" version="2.10.2" targetFramework="net46" />
  <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net46" />
  <package id="NWebsec" version="5.1.1" targetFramework="net46" />
  <package id="NWebsec.Core" version="2.1.0" targetFramework="net46" />
  <package id="NWebsec.Mvc" version="5.1.1" targetFramework="net46" />
  <package id="Owin" version="1.0" targetFramework="net46" />
  <package id="Respond" version="1.4.2" targetFramework="net46" />
  <package id="Sendgrid" version="6.3.0" targetFramework="net46" />
  <package id="SendGrid.SmtpApi" version="1.3.1" targetFramework="net46" />
  <package id="Serilog" version="2.6.0" targetFramework="net46" />
  <package id="Serilog.Enrichers.Environment" version="2.1.2" targetFramework="net46" />
  <package id="Serilog.Sinks.File" version="3.2.0" targetFramework="net46" />
  <package id="Serilog.Sinks.RollingFile" version="3.3.0" targetFramework="net46" />
  <package id="Serilog.Sinks.Sentry" version="2.1.4" targetFramework="net46" />
  <package id="SerilogWeb.Classic" version="2.1.17" targetFramework="net46" />
  <package id="SharpRaven" version="2.2.0" targetFramework="net46" />
  <package id="System.Data.SQLite" version="1.0.108.0" targetFramework="net46" />
  <package id="System.Data.SQLite.Core" version="1.0.108.0" targetFramework="net46" />
  <package id="System.Data.SQLite.EF6" version="1.0.108.0" targetFramework="net46" />
  <package id="System.Data.SQLite.Linq" version="1.0.108.0" targetFramework="net46" />
  <package id="Twitter.Bootstrap.Less" version="3.3.4" targetFramework="net46" />
  <package id="WebActivatorEx" version="2.0.6" targetFramework="net46" />
  <package id="WebGrease" version="1.6.0" targetFramework="net46" />
  <package id="YUICompressor.NET" version="2.7.0.0" targetFramework="net46" />
</packages>

When publishing the app using VS2017 to the file system I get the following warning in the output:

> The following assembly has dependencies on a version of the .NET > Framework that is higher than the target and might not load correctly > during runtime causing a failure: netstandard, Version=2.0.0.0, > Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51. The dependencies > are: System.Transactions, Version=4.0.0.0, Culture=neutral, > PublicKeyToken=b77a5c561934e089. You should either ensure that the > dependent assembly is correct for the target framework, or ensure that > the target framework you are addressing is that of the dependent > assembly.

But I can't find anything on System.Transactions. How can I search what's referencing it?

asp.net Solutions


Solution 1 - asp.net

I think the solution might be this issue on GitHub:

> Try add netstandard reference in web.config like this:" > > > > > > > >

I realise you're using 4.6.1 but the choice of .NET 4.7.1 is significant as older Framework versions are not fully compatible with .NET Standard 2.0.

I know this from painful experience, when I introduced .NET Standard libraries I had a lot of issues with NUGET packages and references breaking. The other change you need to consider is upgrading to PackageReferences instead of package.config files.

See this guide and you might also want a tool to help the upgrade. It does require a late VS 15.7 version though.

Solution 2 - asp.net

Manually editing the .csproj file and adding the reference below worked for me.

<Reference Include="netstandard" />

Thank you to Fahad Alshaya who suggested it here.

Solution 3 - asp.net

I had to do a combination of other people's answers on this thread.

  1. Install the NetStandard.Library via NuGet
  2. Manually editing the .csproj file and adding the reference. <Reference Include="netstandard" />
  3. Expanding project-->References in the VS Solution Explorer, right clicking on 'netstandard' and showing the properties page and setting "Copy Local" to true.

Solution 4 - asp.net

Deleting Bin and Obj folders worked for me.

Solution 5 - asp.net

After upgrading from 4.6.1 framework to 4.7.2 we started getting this error:

"The type 'System.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'." and ultimately the solution was to add the "netstandard" assembly reference mentioned above:

<compilation debug="true" targetFramework="4.7.1" >
    <assemblies>
      <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, 
            PublicKeyToken=cc7b13ffcd2ddd51"/>
    </assemblies>
  </compilation>

Solution 6 - asp.net

I have run into this before and trying a number of things has fixed it for me:

  • Delete a bin folder if it exists
  • Delete the hidden .vs folder
  • Make sure the 4.6.1 targeting pack is installed
  • Last Ditch Effort: Add a reference to System.Runtime (right click project -> add -> reference -> tick the box next to System.Runtime), although I think I've always figured out one of the above has solved it instead of doing this.

Also, if this is a .net core app running on the full framework, I've found you have to include a global.json file at the root of your project and point it to the SDK you want to use for that project:

{
  "sdk": {
    "version": "1.0.0-preview2-003121"
  }
}

Solution 7 - asp.net

Although this is an old thread, I had the same issue today, last week I updated some NuGet packages and although the MVC website worked OK on my dev machine when I published to the testing server it failed.

I read numerous posts but none worked. I finally compared the DLL's in my local bin to those in the testing server and found that the netstandard.dll was not uploaded, once uploaded the website worked OK, not sure why VS2017 web deploy did not publish the DLL.

Just something to look out for in case none of the above work for you.

Solution 8 - asp.net

enter image description here

Set Copy Enbale to true in netstandard.dll properties.

Open Solution Explorer and right click on netstandard.dll. Set Copy Local to true.

Solution 9 - asp.net

Might have todo with one of these:

  1. Install a newer SDK.
  2. In .csproj check for Reference Include="netstandard"
  3. Check the assembly versions in the compilation tags in the Views\Web.config and Web.config.

Solution 10 - asp.net

I experienced this when upgrading .NET Core 1.1 to 2.1.

I followed the instructions outlined here.

Try to remove <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion> or <NetStandardImplicitPackageVersion> section in the .csproj.

Solution 11 - asp.net

We started getting this error on the production server after deploying the application migrated from 4.6.1 to 4.7.2.

We noticed that the .NET framework 4.7.2 was not installed there. In order to solve this issue we did the following steps:

  1. Installed the .NET Framework 4.7.2 from:

https://support.microsoft.com/en-us/help/4054530/microsoft-net-framework-4-7-2-offline-installer-for-windows 2. Restarted the machine

  1. Confirmed the .NET Framework version with the help of https://stackoverflow.com/questions/1565434/how-do-i-find-the-net-version/58104363#58104363

Running the application again with the .Net Framework 4.7.2 version installed on the machine fixed the issue.

Solution 12 - asp.net

Those who are not having web.config file. Output Type other than web application. update the project file (.csproj) with below give code.

It may cause due to adding/removing the .netframework in improper way or it may broke unexpected way.

  <ItemGroup>
    <Reference Include="netstandard" />
  </ItemGroup>

Output Type

  • Console application
  • Class Library

Solution 13 - asp.net

This is where netstandard.dll exists: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\Facades\netstandard.dll Add ref to your Project through this.

Solution 14 - asp.net

I am facing Same Problem i do following Setup Now Application Work fine

1-

<compilation debug="true" targetFramework="4.7.1">
      <assemblies>
        <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, 
      PublicKeyToken=cc7b13ffcd2ddd51"/>
      </assemblies>
    </compilation>

2- Add Reference

 **C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\Common7\IDE\Extensions\Microsoft\ADL
 Tools\2.4.0000.0\ASALocalRun\netstandard.dll**

3-

Copy Above Path Dll to Application Bin Folder on web server

Solution 15 - asp.net

I was facing this problem when trying to add a .NETStandard dependency to a .NET4.6.1 library, and compiling it in Linux with Mono 4.6.2 (the version that comes with Ubuntu 16.04).

I finally solved it today; the solution requires to do both of these things:

  1. Change <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> to <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> in the .csproj file.
  2. Upgrade your mono to a newer version. I believe 5.x should work, but to be sure, you can just install Ubuntu 20.04 (which at the time of writing is only in preview), which includes Mono 6.8.0.105.

Solution 16 - asp.net

You can add to your web.config in your project.

It wouldn't work when you add it to projects web.config because it works with MVC.

Solution 17 - asp.net

The solution of Quango in is working but I prefer to resolve it by adding this code in my Web.config like new projects :

<system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>

Solution 18 - asp.net

I have the same problem with a net5.0 project, which includes a buildtask written using netstandard2.0

<Project>

  <Target Name="RestoreBuildTasks">
    <MSBuild Projects="../../../BuildTasks/BuildTasks.csproj" Targets="Restore" Properties="Configuration=Release"/>
  </Target>

  <Target Name="BuildBuildTasks">
    <MSBuild Projects="../../../BuildTasks/BuildTasks.csproj" Targets="Build" Properties="Configuration=Release"/>
  </Target>

  <UsingTask
      TaskName="Brick.Build.NugetTask"
      AssemblyFile="AGXBrick/BuildTasks/bin/$(Platform)/Release/netstandard2.0/BuildTasks.dll"/>

  <Target Name="CheckNuGetSources" BeforeTargets="Restore" DependsOnTargets="RestoreBuildTasks;BuildBuildTasks">
      <NuGetTask />
  </Target>

</Project>

Where the BuildTasks.csproj looks like this

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>

I was able to resolve this by explicitly setting TargetFramework=netstandard2.0 in the MSBuild task:

    <MSBuild Projects="../../../BuildTasks/BuildTasks.csproj" Targets="Restore" Properties="Configuration=Release;TargetFramework=netstandard2.0"/>

Solution 19 - asp.net

I got same issue, my project use .net framework 4.6.1, and when I use latest MSBuild(16.10.2) to build solution, I got an error message, e.g. ValueType ... you must reference netstandard 2.0.....

I figured it out by installing .Net SDK item, when you select this item, .NET 5.0 runtime and .NET 3.1 Runtime will be installed as well.

enter image description here

After I installed this item, I can build my project with latest MSBuild and no errors!

Solution 20 - asp.net

I had the same issue that would show up every once and a while, probably due to switching branches.

Using 4.6.1. Visual studio 2019, resharper...

My solution was to manually add a new reference, browse to the netstandard.dll, add it, build (errors galore), remove the reference, build again (no errors).

Solution 21 - asp.net

For me it was as simple as the framework being set wrong in the web.config file.

Solution is 4.8 but the web.config was 4.5.1

From

<httpRuntime requestValidationMode="2.0" maxRequestLength="8192" executionTimeout="110" targetFramework="4.5.1" />

To

<httpRuntime requestValidationMode="2.0" maxRequestLength="8192" executionTimeout="110" targetFramework="4.8" />

Solution 22 - asp.net

In my case I've updated my VS 2019 to the latest version as of 05/21, but still got the same issue.

I resolved it by

  1. carefully looking at the error message The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'system.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  2. Open .csproj file and under <ItemGroup> tag add a new <Reference> tag as below
  • <Reference Include="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  1. Follow VS prompt for a project reload, and re-build and I didn't see the same issue.

Solution 23 - asp.net

This issue is based on your installed version of visual studio and Windows, you can follow the following steps:-

  1. Go to Command Window

  2. downgraded your PCL by the following command

     Install-Package Xamarin.Forms -Version 2.5.1.527436
    
  3. Rebuild Your Project.

  4. Now You will able to see the required output

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionempzView Question on Stackoverflow
Solution 1 - asp.netQuangoView Answer on Stackoverflow
Solution 2 - asp.netkamilkView Answer on Stackoverflow
Solution 3 - asp.netDamien SawyerView Answer on Stackoverflow
Solution 4 - asp.netVijay VermaView Answer on Stackoverflow
Solution 5 - asp.netRaghavView Answer on Stackoverflow
Solution 6 - asp.netKyle DodgeView Answer on Stackoverflow
Solution 7 - asp.netGeorge PhillipsonView Answer on Stackoverflow
Solution 8 - asp.netHani Abu khurmaView Answer on Stackoverflow
Solution 9 - asp.netIgorView Answer on Stackoverflow
Solution 10 - asp.neth-raiView Answer on Stackoverflow
Solution 11 - asp.netRaghavView Answer on Stackoverflow
Solution 12 - asp.netThiyaView Answer on Stackoverflow
Solution 13 - asp.netHarshil ParekhView Answer on Stackoverflow
Solution 14 - asp.netMansoorView Answer on Stackoverflow
Solution 15 - asp.netknocteView Answer on Stackoverflow
Solution 16 - asp.netMEOView Answer on Stackoverflow
Solution 17 - asp.netk4st0r42View Answer on Stackoverflow
Solution 18 - asp.netkolisView Answer on Stackoverflow
Solution 19 - asp.netdawncoldView Answer on Stackoverflow
Solution 20 - asp.netuser1314413View Answer on Stackoverflow
Solution 21 - asp.netNeil McQuillanView Answer on Stackoverflow
Solution 22 - asp.netKiran ModiniView Answer on Stackoverflow
Solution 23 - asp.netRakendu ShuklaView Answer on Stackoverflow