C# – Build error: You must add a reference to System.Runtime

asp.net-mvccportable-class-library

I'm preparing a brand new ASP.NET MVC 5.1 solution. I'm adding in a bunch of NuGet packages and setting it up with Zurb Foundation, etc.

As part of that, I've added a reference to an in-house NuGet package which is a Portable Class Library and I think this is causing a problem on the build server.

TeamCity fails the build with:

The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0

I originally added the fix for the same or similar error when compiling the Razor web pages, that fix being in the web.config

<compilation ... >
  <assemblies>
    <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </assemblies>
</compilation>

However, the issue is unresolved.

Best Answer

To implement the fix, first expand out the existing web.config compilation section that looks like this by default:

<compilation debug="true" targetFramework="4.5"/>

Once expanded, I then added the following new configuration XML as I was instructed:

  <assemblies>     
    <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />   
  </assemblies>

The final web.config tags should look like this:

<compilation debug="true" targetFramework="4.5">
  <assemblies>     
    <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />   
  </assemblies>
</compilation>