2

I have seen a previous SO Question here that discusses a similar (identical?) issue, but there was no answer there that could satisfy my problem.

My Environment:

MonoDevelop 3.0.3.2
Installation UUID: ????????
Runtime:
    Mono 2.10.9 (tarball)
    GTK 2.24.10
    GTK# (2.12.0.0)
    Package version: 210090011
Mono for Android not installed
Apple Developer Tools:
     Xcode 4.3.3 (1178)
     Build 4E3002
Monotouch: 5.2.12
Build information:
    Release ID: 30003002
    Git revision: 7bf6ac0ca43c1b12703176ad9933c3484c05c84c-dirty
    Build date: 2012-06-16 04:36:10+0000
    Xamarin addins: 62ad7268d38c2ece7e00dc32960bd3bdab8fec38
Operating System:
    Mac OS X 10.7.4
    Darwin NEWTON.local 11.4.0 Darwin Kernel Version 11.4.0
        Mon Apr  9 19:32:15 PDT 2012
        root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64

My Code (Ping & PingResponse are DTOs in my own ServiceModel library):

Ping request = new Ping { LoginInfo = new IMDSSWebService_SS.ServiceModel.ClientLoginInfo { UserName="guest", Password="guest", ClientPlatform="iOS", ClientVersion="1.5", InstanceUID="uid1"} };
var response = _appDel.ServiceClient.Send<IMDSSWebService_SS.ServiceModel.PingResponse>(request);

ServiceStack Libraries:

ServiceStack.Common.Monotouch.dll (built from git src)
ServiceStack.Interfaces.Monotouch.dll (built from git src)
ServiceStack.Text.Monotouch (built from git src)

Exception:

System.ExecutionEngineException has been thrown

Attempting to JIT compile method 'ServiceStack.Text.Json.JsonReader`1:GetParseFn ()' while running with --aot-only.

System.ExecutionEngineException: Attempting to JIT compile method 'ServiceStack.Text.Json.JsonReader`1:GetParseFn ()' while running with --aot-only.

  at ServiceStack.Text.Json.JsonReader.GetParseFn (System.Type type) [0x00000] in :0
  at ServiceStack.Text.Json.JsonTypeSerializer.GetParseFn (System.Type type) [0x00000] in :0
  at ServiceStack.Text.Common.TypeAccessor.Create (ITypeSerializer serializer, ServiceStack.Text.TypeConfig typeConfig, System.Reflection.PropertyInfo propertyInfo) [0x00000] in :0
  at ServiceStack.Text.Common.DeserializeType`1[ServiceStack.Text.Json.JsonTypeSerializer].GetParseMethod (ServiceStack.Text.TypeConfig typeConfig) [0x00000] in :0
  at ServiceStack.Text.Common.JsReader`1[ServiceStack.Text.Json.JsonTypeSerializer].GetParseFn[PingResponse] () [0x00000] in :0
  at ServiceStack.Text.Json.JsonReader`1[IMDSSWebService_SS.ServiceModel.PingResponse]..cctor () [0x00000] in :0

I did try calling JsConfig.RegisterForAot(), but that didn't change anything. I also tried various permutations of Link SDK Only, Link All, Link None, but all failed either with the above exception, or didn't build at all, see below.

Simulator/Debug - Works Fine
Simulator/Release - Works Fine
iPhone/Debug - Exception Above
iPhone/Release - Doesn't even build. (will create a separate SO question)
Community
  • 1
  • 1
pseabury
  • 1,615
  • 3
  • 16
  • 30

1 Answers1

4

I added a Type Registration function to ServiceStack.Text.Monotouch.JsConfig.cs that lets you register your custom DTOs for AOT compilation. There is a pull request to the ServiceStack mainline, so this should make it in soon.

JsConfig Code Change

You need to register all of your Response DTO Types that aren't standard C# types (string, int, etc.). My PingResponse DTO includes a StatusEnum Enumeration, so I have to register both before I can Parse a response without throwing a JIT Exception. Using the patch above, I would call the following in my Monotouch App:

JsConfig.RegisterForAot();
JsConfig.RegisterTypeForAot<PingResponse>();
JsConfig.RegisterTypeForAot<StatusEnum>();

This could get really messy for Complicated DTOs. Hopefully someone (maybe I will if time permits) can come up with an automated way of discovering all types in your DTO that should be registered? Maybe reflection?

pseabury
  • 1,615
  • 3
  • 16
  • 30