xamarin.ios - MonoTouch 上的 ServiceStack JIT 错误

标签 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

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

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

我确实尝试调用 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)

最佳答案

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

JsConfig Code Change

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

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

这对于复杂的 DTO 来说可能会变得非常困惑。希望有人(如果时间允许的话也许我会)能够想出一种自动的方法来发现 DTO 中应该注册的所有类型?也许是反射(reflection)?

关于xamarin.ios - MonoTouch 上的 ServiceStack JIT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11385586/

相关文章:

c# - Xamarin 需要引用 Windows.Foundation.FoundationContract

iphone - 带有 MonoTouch 的 Google Analytics 在设备上崩溃

ios - Xamarin.iOS:使用附加对象创建自定义按钮

ios - 为什么 UIFont.LineHeight 是只读的?

c# - 使用 ServiceStack 反序列化嵌套 JSON 对象

.net - redis在用户注册时如何处理并发写请求

c# - 使用 MonoTouch 在 iOS 上自定义 Switch

authentication - 将 [Authenticate] 与 BasicAuthProvider 一起使用时出现 401 错误

c# - ServiceStack.Redis : PooledRedisClientManager creating way too many connections

asp.net-mvc-3 - "Who is online"ServiceStack 功能