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

The Most Promising Open Source Projects to Watch for in 2018 flip.it/PC-YkD
Relaxing day, catching up on .NET CORE 2 release information. #Microsoft #AspNetCore https://t.co/xpTV1PQzt4
Retweeted by @dyardy .@terrajobst & @runfaster2000 demo features of #dotNET Standard on @ch9! Watch: msft.social/2QPLe7 https://t.co/Wz3YeJLmcC
Retweeted by @dyardy Now on the latest Xamarin Show Snack Pack: Optimized Lists w/ DataTemplate Selectors in Xamarin.Forms,… twitter.com/i/web/status/9…
Retweeted by @dyardy CodeRush for Roslyn 17.1.8 is Available dlvr.it/Pp9fl6 https://t.co/oqLqrp6QVK