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


This issue was not unlike others that I have come up against with my cross-device mobile development efforts.

- February 12, 2017

Rest of the Story:

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 ActiveError 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 ActiveError 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 ActiveError 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 ActiveError 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 ActiveError 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 ActiveError 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 ActiveError 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 ActiveError 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 ActiveError 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>