This project has moved. For the latest updates, please go here.


TypeLoadException when using PCL version inside an other PCL



I'm facing a blocking problem...
I have a project (iOS, in this case), referencing a PCL (made by me), which itself references Newtonsoft.Json portable
App --> My PCL --> Newtonsoft.Json

Everything compiles just fine, but at runtime, when using a method of my PCL which calls Newtonsoft.Json, I get a TypeLoadException

I'm able to reproduce this issue on a fresh new project, see attachment (Xamarin.iOS project)
A simple PCL, referencing Newtonsoft.JSon, with a single class like this:
    public class MyClass {
        public int Test() {
            var json = @"{""t"":16,""s"":""test""}";
            var o = JObject.Parse(json);
            return o["t"].Value<int>();
A simple App, with a single button, with this event handler:
    partial void Test() {
        var c = new MyClass();
        var i = c.Test();
        new UIAlertView("", i.ToString(), null, "Close").Show();
I get a TypeLoadException when tapping the button, on line "var i = c.Test();" !

Even weirder, when replacing this:
return o["t"].Value<int>();
with this:
return (int)o["t"];
I'm not getting a TypeLoadException, but a MissingMemberException, with this message:
Missing method Newtonsoft.Json.Linq.JToken::op_Explicit(JToken) in assembly /Users/Ingham/Projects/TestPCL-iOS/TestPCL-iOS/bin/iPhoneSimulator/Debug/Newtonsoft.Json.dll, referenced in assembly /Users/Ingham/Projects/TestPCL-iOS/TestPCL/bin/Debug/TestPCL.dll
I really can't see what I'm doing wrong...
I've tried many combinations of possible profiles for my PCL,, but nothing works...

Thanks in advance !

file attachments

Closed Dec 26, 2013 at 5:26 AM by JamesNK
I don't have Xamarin. Ask them.