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.
It's an old issue but I faced it today in order to fix a build pipeline on our continuous integration server. Adding
to my
.csproj
file solved the problem for me.A bit of context: the interested project is a full .Net framework 4.6.1 project, without build problem on the development machines. The problem appears only on the build server, which we can't control, may be due to a different SDK version or something similar.
Adding the proposed
<Reference
solved the build error, at the price of a missing reference warning (yellow triangle on the added entry in the references tree) in Visual Studio.I hope this can help people in similar scenarios...
I was also facing this problem trying to run an ASP .NET MVC project after a minor update to our codebase, even though it compiled without errors:
Our project had never run into this problem, so I was skeptical about changing configuration files before finding out the root cause. From the error logs I was able to locate this detailed compiler output which pointed out to what was really happening:
Apparently a new package added to our project was referencing an older version of the .NET Framework, causing the "definition in multiple assemblies" issue (CS1685), which led to the razor view compiler error at runtime.
I removed the incompatible package (System.Collections.Immutable.dll) and the problem stopped occurring. However, if the package cannot be removed in your project you will need to try Baahubali's answer.
Removing the reference over the Nuget Package Manager and re-adding it solved the problem for me.