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

Another day, another issue while building a Xamarin project. In this case, I was building a project from Xamarin and working through some logic.  When building the Android project I was presented with the following build errors.

I am getting use to different errors at the most unexpected times.  This issue was not unlike others that I have come up against with my cross-device mobile development efforts.  The good news, after much hunting and packing I found the solution.  See below.

image

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS0012    The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.    GreatQuotes.Android    C:\Xamarin\10a_xam300\Lab Materials\Part 01 Resources\Start\GreatQuotes.Android\App.cs    9    Active
Error    CS0234    The type or namespace name 'TargetFrameworkAttributeAttribute' does not exist in the namespace 'System.Runtime.Versioning' (are you missing an assembly reference?)    GreatQuotes.Android    C:\Users\dyardy\AppData\Local\Temp\MonoAndroid,Version=v7.1.AssemblyAttributes.cs    4    Active
Error    CS0234    The type or namespace name 'TargetFrameworkAttribute' does not exist in the namespace 'System.Runtime.Versioning' (are you missing an assembly reference?)    GreatQuotes.Android    C:\Users\dyardy\AppData\Local\Temp\MonoAndroid,Version=v7.1.AssemblyAttributes.cs    4    Active
Error    CS0518    Predefined type 'System.String' is not defined or imported    GreatQuotes.Android    C:\Users\dyardy\AppData\Local\Temp\MonoAndroid,Version=v7.1.AssemblyAttributes.cs    4    Active
Error    CS0246    The type or namespace name 'FrameworkDisplayName' could not be found (are you missing a using directive or an assembly reference?)    GreatQuotes.Android    C:\Users\dyardy\AppData\Local\Temp\MonoAndroid,Version=v7.1.AssemblyAttributes.cs    4    Active
Error    CS0518    Predefined type 'System.String' is not defined or imported    GreatQuotes.Android    C:\Users\dyardy\AppData\Local\Temp\MonoAndroid,Version=v7.1.AssemblyAttributes.cs    4    Active
Error    CS0518    Predefined type 'System.Object' is not defined or imported    GreatQuotes.Android    C:\Xamarin\10a_xam300\Lab Materials\Part 01 Resources\Start\GreatQuotes.Android\App.cs    9    Active
Error    CS0518    Predefined type 'System.Void' is not defined or imported    GreatQuotes.Android    C:\Xamarin\10a_xam300\Lab Materials\Part 01 Resources\Start\GreatQuotes.Android\App.cs    9    Active
Error    CS0012    The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.    GreatQuotes.Android    C:\Xamarin\10a_xam300\Lab Materials\Part 01 Resources\Start\GreatQuotes.Android\App.cs    9    Active
Error    CS0246    The type or namespace name 'Icon' could not be found (are you missing a using directive or an assembly reference?)    GreatQuotes.Android    C:\Xamarin\10a_xam300\Lab Materials\Part 01 Resources\Start\GreatQuotes.Android\App.cs    9    Active
Error    CS0518    Predefined type 'System.Object' is not defined or imported    GreatQuotes.Android    C:\Xamarin\10a_xam300\Lab Materials\Part 01 Resources\Start\GreatQuotes.Android\App.cs    9    Active
Error    CS0518    Predefined type 'System.String' is not defined or imported    GreatQuotes.Android    C:\Xamarin\10a_xam300\Lab Materials\Part 01 Resources\Start\GreatQuotes.Android\App.cs    9    Active
Error    CS0012    The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.    GreatQuotes.Android    C:\Xamarin\10a_xam300\Lab Materials\Part 01 Resources\Start\GreatQuotes.Android\App.cs    9    Active

 

The solution (to make a very long story short) was to unload the project from Visual Studio.  Open the csproj and add the following reference (in bold).  I initially was comparing some of my working Android projects with this one that just would not build. I noticed the reference to mscorlib.  I tried to add a reference to this dll directly through ‘Add Reference’ but I got the following error "mscorlib.dll" component is already automatically referenced.  The build system should add this reference for you.

 

Since I could not add through the VS.NET interface, i chose to add via csproj file.  After reloading the project and rebuilding the reference to mscorlib was visible in the list of references and finally my project built fine.

<ItemGroup>
  <Reference Include="Mono.Android" />
  <Reference Include="mscorlib" />
  <Reference Include="System" />
  <Reference Include="System.Xml" />
  <Reference Include="System.Core" />
  <Reference Include="System.Xml.Linq" />
</ItemGroup>

Author

david

comments powered by Disqus

Categories

Recent Tweets

Retweeted by @dyardy Yo, I could watch professional tag all day. https://t.co/Dk0b0I3AS7
Photos That Will Change The Way You See The World youtube.com/watch?v=PPRD5C…
Evaluating iPod shuffle with daily workout #ipod #apple Did I mention UNDER WATER https://t.co/WbxY2mNSNm
Retweeted by @dyardy Our partnership with Microsoft @Azure brings you a collection of great Pluralsight courses—for free! See them now: plrsig.ht/2tVXSkr