MonoTouch上的ServiceStack JIT错误

时间:2012-07-08 18:31:17

标签: xamarin.ios servicestack

我之前见过一个SO Question here来讨论一个类似的(相同的?)问题,但没有答案可以解决我的问题。

我的环境:

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

我的代码(Ping& PingResponse是我自己的ServiceModel库中的DTO):

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库:

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

例外:

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

我确实尝试过调用JsConfig.RegisterForAot(),但这并没有改变任何东西。我还尝试了Link SDK Only,Link All,Link None的各种排列方式,但是都失败了,或者根本没有构建,请参见下文。

Simulator/Debug - Works Fine
Simulator/Release - Works Fine
iPhone/Debug - Exception Above
iPhone/Release - Doesn't even build. (will create a separate SO question)

1 个答案:

答案 0 :(得分:4)

我在ServiceStack.Text.Monotouch.JsConfig.cs中添加了一个类型注册函数,它允许您注册自定义DTO以进行AOT编译。有一个对ServiceStack主线的拉取请求,所以这应该很快就会出现。

JsConfig Code Change

您需要注册所有非标准C#类型的响应DTO类型(字符串,整数等)。我的PingResponse DTO包含StatusEnum枚举,因此我必须先注册这两个,然后才能解析响应而不会抛出JIT异常。使用上面的补丁,我会在我的Monotouch App中调用以下内容:

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

对于复杂的DTO来说,这可能会变得非常混乱。希望有人(如果时间允许的话,也许我会)想出一个自动的方式来发现你的DTO中应该注册的所有类型?也许反思?