0

I just set up a new Windows 2012 R2 machine. MSDN says Windows 2012 R2 has .NET Framework 4.5 included. But when I build a small app that requires .NET 4.5 it throws these compilation errors:

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

How to make this machine able to compile .NET app?

Update
The projects are windows service and ASP.NET MVC 5 website.

Anonymous
  • 9,366
  • 22
  • 83
  • 133

3 Answers3

4

I just ran into a similar problem ("The type 'System.IDisposable' is defined in an assembly...") and found this question right at the top of my search results. lord_alek1s link did contain the fix for this issue so, in an effort to help expand his answer, i'll post the config change that link describes.

Most likely your compilation tag in Web.config will look like this:

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

Change it to include an assembly for System.Runtime like so:

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

And the reason for this error is explained in another SO question: What does the web.config compilation/assemblies element do?

Community
  • 1
  • 1
Mungoid
  • 565
  • 5
  • 16
0

I found this question as I had the same error with building a Windows Forms application on Windows Server 2012 R2 so the web.config modification didn't apply to me. However (in case anyone else comes here with the same problem as me) this was fixed by installing the NET Framework 4.6.1 Developer Pack

Badgerspot
  • 2,301
  • 3
  • 28
  • 42
-1

This seems like what they experienced here:

http://www.lyalin.com/2014/04/25/the-type-system-object-is-defined-in-an-assembly-that-is-not-reference-mvc-pcl-issue/

  • 4
    Try and summarise the information in the article because if the link ever breaks or dies your answer is useless for people who visit this page in the future. – Jeremy Thompson Nov 06 '14 at 10:44