Patrick Desjardins Blog
Patrick Desjardins picture from a conference

VisualStudio.com Build Problem With System.Object is defined in an assembly that is not referenced

Posted on: 2014-09-26

Visual Studio 2013 build correctly your Asp.Net MVC under .Net Framework 4.5.2 but when you commit to Visual Studio TFS online the Build Server gives you an error about System.Object. The error that can be something about System.Object that is not defined in an assembled.

Here is the full exception.

Entities\Trading\Portefolio.cs (41): 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, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

This is because Visual Studio on your computer knows to get them by going into a system folders. For example, the folder C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades has a lot of assembly that Visual Studio known on your computer .

To fix this problem you need to open your Web.Config file and add under System.Web a compilation section.

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

An important notion is that the httpRuntime target framework must be the same as the one defined in the compilation. The last thing that might be required is to force msbuild to use the targetframework you want. To do so, open Visual Studio Online or edit within Visual Studio the Build Definition to use the framework 4.5.2 (or the one defined in your web.config). You have to set the framework to the same as the web.config. If you already have argument after /p you just need to append the targetframeworkversion with the framework version desired.

Finally, if you still have problem building with Visual Studio, at the time I am writing this article, the Visual Studio Online team have confirming me that they does not support the latest framework of .Net. This should be solve in few months.