You must add a reference to assembly netstandard

16 Feb 2019

Recently, I tried to update all nuget packages of website while upgrading from .NET framework v4.6 to v4.7. Packages download and installation happened swiftly without any issues, and even the first build succeeded. But on the first run, I encountered following error message;

The type 'System.IEquatable`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

The error was a strange one, because I didn't intentionally refer any package that is meant for .NET Standard framework.

After going through packages.config, I found few nuget packages have started to release just .NET standard and .NET Core version of their libraries after final release for .NET framework v4.6. So my package version upgrade has pulled-in libraries released for .NET Standard 2.0 which is compatible with .NET v4.62+.

For more information on .NET framework compatibility with .NET Standard framework, go through following Microsoft's official document on the .NET framework implementation support.

This change in direction of package owners often comes as a suprise for the dependent projects. This package release & update requires all dependent projects to refer the netstandard assembly in web.config as shown below;

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

Once your are on .NET Standard, your are on a hybrid framework mode. You can consume .NET Standard libraries or a full fledged .NET4.7 libraries (If available).

Hope above information is useful & saves your time.