在 MonoTouch 上使用 ServiceStack JSON 进行序列化时出错
我正在尝试 ServiceStack 的 JSON 引擎。我获取了 MonoTouch 二进制版本 v2.20。在模拟器上工作正常,但在 iOS 设备(iPad2、iOS5)上,我收到 JsonWriter 的类型初始值设定项抛出的异常(除此之外没有什么其他的了)。我正在使用 MonoTouch 5、MonoDevelop 2.8.1,并以 iOS 5 为目标。我已禁用库链接,因为启用时出现错误。
我创建了一个示例并上传到 https://github.com/t9mike/ServiceStack-JSON1。
我正在尝试确定问题是否出在我的编译选项、服务堆栈或 MonoTouch 上。提前致谢。
I am experimenting with ServiceStack's JSON engine. I grabbed the MonoTouch binary build, v2.20. Works fine from simulator, but from the iOS device (iPad2, iOS5) I get an exception thrown by the type initializer for JsonWriter (and not much other than that). I am using MonoTouch 5, MonoDevelop 2.8.1, and targeting iOS 5. I have disabled library linking because I am getting an error when enabled.
I created a sample and uploaded to https://github.com/t9mike/ServiceStack-JSON1.
I'm trying to determine whether the issue is my compilation options, Service Stack, or MonoTouch. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个可能有帮助的快速部分答案:
当前 (5.0) 托管链接器可以消除应用程序中一些未使用的(从静态分析的角度来看)代码。这通常发生在使用全部链接选项时,即链接器处理用户代码的情况。
一种替代方法是仅使用不接触用户代码的Link SDK 程序集(只有 MonoTouch 本身附带的代码才会由链接器处理)。
另一种选择是在代码中添加
[Preserve]
属性,以确保链接器处理代码后仍然满足序列化器要求。有关链接器和 [Preserve] 属性的更多信息,请访问此处。MonoTouch 的下一个版本 (5.2) 将在链接器中包含更复杂的步骤,以确保基本的 XML 序列化和 DataContract 要求不会被破坏。不确定这是否能解决这个特定情况(ServiceStack JSON),但我会研究一下。
至于你问题的其余部分,我将尝试自己构建并复制你的问题。
A quick partial answer that might help:
The current (5.0) managed linker can eliminate some unused (from a static analysis point of view) code from your application. This generally occurs when using Link all option, i.e. where user code gets processed by the linker.
One alternative is using the Link SDK assemblies only that won't touch the user code (only the code shipped with MonoTouch itself will be processed by the linker).
Another alternative is adding
[Preserve]
attributes on your code to ensure the serializer requirements are still met after the linker has processed your code. More information about the linker and [Preserve] attributes can be found here.The next (5.2) release of MonoTouch will include a bit more sophisticated step in the linker to ensure the basic XML serialization and DataContract requirements are not broken. Not sure if this will solve this specific case (ServiceStack JSON) but I'll have a look into it.
As for the rest of your question I'll try to build this myself and duplicate your issue.
我最终从 GitHub 获取了 ServiceStack.Text 源 ,版本3.0.3。我创建了一个新的 MonoTouch 库项目。我必须稍微调整 ServiceStack.Text/JsConfig.cs 以条件化 System.Drawing.Color 位。我将向作者发送补丁和 MT csproj。
使用这个新程序集后,我的示例 MT 应用程序在设备上运行良好。我已经在 https://github.com/t9mike/ServiceStack-JSON1 更新了我的示例新的 ServiceStack.Text dll。
I ended up grabbing the ServiceStack.Text sources from GitHub, version 3.0.3. I created a new MonoTouch library project. I had to tweak ServiceStack.Text/JsConfig.cs slightly to conditionalize away the System.Drawing.Color bits. I'll send a patch and MT csproj to the authors.
After using this new assembly, my sample MT app ran fine on the device. I have updated my sample at https://github.com/t9mike/ServiceStack-JSON1 with the new ServiceStack.Text dll.