Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable Class Library System.Object error

I am using Portable Class Libraries (PCL) in Xamarin Studio on OS X. I have two PCL libraries that are targeting .NET 4.5, Windows Phone 8, Windows Store Apps, Xamarin.iOS, and Xamarin.Android. I reference these two libraries in my iOS, Android, and Unit tests projects. In 3 areas I am getting the following error:

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'.

The code is straightforward:

MyClass myClass = new MyClass();

The error occurs once in each of the projects that reference the PCLs. None of them are the same class. I am new to PCLs. I've tried removing the Windows Phone 8 (as I added it last minute) and yet the problem does not go away. Any help would be appeciated!

Thanks!

Update:

So this occurs with the first field declared in the class (where the class is from the PCL project).

int a = 0;
MyPCLClass _myPCLClass = new MyPCLClass();  //This is where the error appears

Another odd aspect is that there are over 50 classes using these classes, and the error is only appearing in three classes.

like image 367
JamWils Avatar asked Jul 20 '13 19:07

JamWils


1 Answers

I just ran into this exact same problem, and have the same setup as you do. A tip mentioned in a comment (by Stuart, which in turn mentioned a tweet by @DavKean) to this question solved it for me.

You have to:

  • access a Windows machine (I used a Windows 8)
  • grab C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.Runtime.dll
  • copy it to your Mac
  • add a reference to this dll from each of your iOS and Droid projects
like image 192
AlanP Avatar answered Sep 28 '22 01:09

AlanP