JSON.NET: Not working with MonoTouch "Ran out of trampolines of type 2 "

540 views Asked by At

I have tried the JSON.NET and the MonoTouch port at https://github.com/ayoung/Newtonsoft.Json but get this Serialization error:

Ran out of trampolines of type 2 in '/private/var/mobile/Applications/A901C3E6-D9AB-44AF-AA13-6B6E44467BAE/StaffRostering.app/mscorlib.dll' (128)

Stacktrace:

at Newtonsoft.Json.Serialization.DefaultContractResolver.GetParametrizedConstructor (System.Type) [0x00009] in /Users/vink/Dropbox/Ajilon Source/Apps/Utils/Newtonsoft.Json.MonoTouch/Newtonsoft.Json/Serialization/DefaultContractResolver.cs:336
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type) [0x000ae] in /Users/vink/Dropbox/Ajilon Source/Apps/Utils/Newtonsoft.Json.MonoTouch/Newtonsoft.Json/Serialization/DefaultContractResolver.cs:310
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type) [0x000b0] in /Users/vink/Dropbox/Ajilon Source/Apps/Utils/Newtonsoft.Json.MonoTouch/Newtonsoft.Json/Serialization/DefaultContractResolver.cs:675
at Newtonsoft.Json.Utilities.ThreadSafeStore`2.AddValue (TKey) <0x000bf>
at Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get (TKey) <0x00173>
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type) [0x00011] in /Users/vink/Dropbox/Ajilon Source/Apps/Utils/Newtonsoft.Json.MonoTouch/Newtonsoft.Json/Serialization/DefaultContractResolver.cs:196
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (object) [0x00008] in /Users/vink/Dropbox/Ajilon Source/Apps/Utils/Newtonsoft.Json.MonoTouch/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs:86
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter,object) [0x00011] in /Users/vink/Dropbox/Ajilon Source/Apps/Utils/Newtonsoft.Json.MonoTouch/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs:70
at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter,object) [0x00012] in /Users/vink/Dropbox/Ajilon Source/Apps/Utils/Newtonsoft.Json.MonoTouch/Newtonsoft.Json/JsonSerializer.cs:451
at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter,object) [0x00000] 

I tried RestSharp.Monotouch as well and get a similar error:

Ran out of trampolines of type 2 in '/private/var/mobile/Applications/A901C3E6-D9AB-44AF-AA13-6B6E44467BAE/StaffRostering.app/mscorlib.dll' (128)

Stacktrace:

at RestSharp.Reflection.SafeDictionary`2.GetEnumerator () <0x000ab>
at RestSharp.PocoJsonSerializerStrategy.TrySerializeUnknownTypes (object,object&) <IL 0x0002b, 0x00247>
at RestSharp.PocoJsonSerializerStrategy.SerializeNonPrimitiveObject (object,object&) <IL 0x00010, 0x000e7>
at RestSharp.SimpleJson.SerializeValue (RestSharp.IJsonSerializerStrategy,object,System.Text.StringBuilder) <IL 0x000f7, 0x00e1b>
at RestSharp.SimpleJson.SerializeObject (object,RestSharp.IJsonSerializerStrategy) <IL 0x0000e, 0x000eb>
at RestSharp.SimpleJson.SerializeObject (object) <IL 0x00006, 0x0008f>
at RestSharp.Serializers.JsonSerializer.Serialize (object) <IL 0x00001, 0x00083>
1

There are 1 answers

2
Ian Vink On BEST ANSWER

Here's the solution:

Ran out of trampolines of type 2

If you make heavy use interfaces, you may get this message on device. You can create more type 2 trampolines (type IMT Thunks) by modifying your project options "iPhone Build" section. You want to add extra arguments for the Device build targets:

-aot "nimt-trampolines=512"

The default number of IMT Thunk trampolines is 128. Try increasing this number until you have enough for your usage of interfaces.

I have no clue what a trampoline is....