如何以Xamarin形式使用消息包

发现错误280猴子

我必须使用MessagePack来反序列化从Web API(ASP.net)返回的数据,该Web API使用相同的程序包进行了序列化。

使用以下代码

public async static Task<T> DeserializeAsync<T>(Stream stream)
{
    if (stream == null)
    {
        throw new ArgumentNullException(nameof(stream), "Stream value cannot be null");
    }
     
    stream.Position = 0;
    T deserialized = await MessagePackSerializer.DeserializeAsync<T>(stream, MessagePack.Resolvers.ContractlessStandardResolver.Options).ConfigureAwait(false);
    return deserialized;
}

在Android的调试模式下一切正常,但在iOS的调试和发行版以及Android发行模式下,一切正常。反序列化代码崩溃,但出现以下异常

Android -> Release 

[MonoDroid]   at MessagePa07-10 18:06:01.269 I/MonoDroid(13495): MessagePack.MessagePackSerializationException: Failed to deserialize Project.Core.Models.SomeData Class value. ---> System.TypeInitializationException: The type initializer for 'FormatterCache`1' threw an exception. ---> MessagePack.Internal.MessagePackDynamicObjectResolverException: can't find public constructor. type:System.Drawing.Drawing2D.Matrix
[MonoDroid]   at MessagePack.Internal.ObjectSerializationInfo.CreateOrNull (System.Type type, System.Boolean forceStringKey, System.Boolean contractless, System.Boolean allowPrivate) [0x009a0] in <23c4c9b023514c20801c8f07fd69206c>:0 
[MonoDroid]   at MessagePack.Internal.DynamicObjectTypeBuilder.BuildType (MessagePack.Internal.DynamicAssembly assembly, System.Type type, System.Boolean forceStringKey, System.Boolean contractless) [0x00015] in <23c4c9b023514c20801c8f07fd69206c>:0 

iOS->
System.TypeInitializationException: The type initializer for 'Project.Core.Helpers.BinarySerializer' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MessagePack.Resolvers.ContractlessStandardResolver' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MessagePack.Internal.StandardResolverHelper' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MessagePack.Resolvers.DynamicEnumResolver' threw an exception. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
  at MessagePack.Internal.DynamicAssembly..ctor (System.String moduleName) [0x0001a] in <f04e2061de5c414991b8e36a20354820>:0 
  at MessagePack.Resolvers.DynamicEnumResolver..cctor () [0x00010] in <f04e2061de5c414991b8e36a20354820>:0 
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
  at MessagePack.Internal.StandardResolverHelper..cctor () [0x00000] in <f04e2061de5c414991b8e36a20354820>:0 
   --- End of inner exception stack trace ---

在MessagePack git页面中找到该部分,指定使用提前时间代码生成器解决此问题的方法。我按照步骤操作,但无法解决问题。另外,我确定我做得对。

如何在Xamarin.Forms中使用MessagePack。任何人都可以建议我或提供参考。

更新后续步骤

  1. 单击按钮即可使用消息包序列化。
  2. 已安装MPC工具。
  3. 请勿使用mpc -i“ {FormsProject.csproj路径}” -o“ {FormsProject目录路径}”
  4. 将创建的消息包生成的类添加到表单项目。
  5. 在App.xaml.csInitialize方法中使用了以下代码
StaticCompositeResolver.Instance.Register(
     MessagePack.Resolvers.GeneratedResolver.Instance,
     MessagePack.Resolvers.StandardResolver.Instance

现在(平台不支持该操作)也会引发异常。我不太明白我在这里干什么。

更新2:

例外 MessagePackSerializerOptions

System.TypeInitializationException: The type initializer for 'MessagePackSerializerOptionsDefaultSettingsLazyInitializationHelper' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MessagePack.Resolvers.StandardResolver' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MessagePack.Internal.StandardResolverHelper' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MessagePack.Resolvers.DynamicEnumResolver' threw an exception. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
  at System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.pns.cs:129 
  at MessagePack.Internal.DynamicAssembly..ctor (System.String moduleName) [0x0001a] in <f04e2061de5c414991b8e36a20354820>:0 
  at MessagePack.Resolvers.DynamicEnumResolver..cctor () [0x00010] in <f04e2061de5c414991b8e36a20354820>:0 
发现错误280猴子

升级到MessagePack2.1.165或更高版本。

此问题已在2.1.165版的消息包中修复。关于的延迟加载DynamicAssembly

发行链接

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何以 xamarin 形式使用 SQLite-Net-PCL?

来自分类Dev

如何以Xamarin形式重叠图像

来自分类Dev

如何以Xamarin形式动态更改CultureInfo

来自分类Dev

如何以Xamarin形式检测设备的大小

来自分类Dev

如何以 xamarin 形式更改屏幕亮度

来自分类Dev

如何以 xamarin 形式播放音频?

来自分类Dev

如何以角度2的形式显示验证消息?

来自分类Dev

如何以角度2的动态形式对验证消息进行反应

来自分类Dev

如何以Rails形式动态使用Rowspan

来自分类Dev

如何以选择形式使用if语句?

来自分类Dev

如何以C ++形式使用TextBox文本?

来自分类Dev

如何以Xamarin形式显示html格式的文本

来自分类Dev

如何以xamarin形式调用同步Web服务调用?

来自分类Dev

如何以Xamarin形式显示进度条通知

来自分类Dev

如何以Xamarin形式获取Samsung Health计步表

来自分类Dev

如何以Xamarin形式水平分布标签

来自分类Dev

如何以Xamarin形式加入BLE通知中的值?

来自分类Dev

如何以xamarin形式调用同步Web服务调用?

来自分类Dev

如何以xamarin形式在xaml中进行动态设计

来自分类Dev

您如何以非静态形式使用Q.all?

来自分类Dev

如何以infix形式使用类型构造函数

来自分类Dev

如何以ASP形式在MVC Core上使用datepicker

来自分类Dev

如何以其他形式使用Ajax响应数据?

来自分类Dev

您如何以非静态形式使用Q.all?

来自分类Dev

如何以表格形式使用Spree身份验证

来自分类Dev

在wtforms中如何以真实形式使用文档中的示例?

来自分类Dev

如何以相同的形式使用来自输入标签的值

来自分类Dev

如何以Twitter Bootstrap水平形式(在输入的右侧)正确地放置警告/错误消息?

来自分类Dev

播放框架:如何以动态形式为特定字段设置错误消息

Related 相关文章

  1. 1

    如何以 xamarin 形式使用 SQLite-Net-PCL?

  2. 2

    如何以Xamarin形式重叠图像

  3. 3

    如何以Xamarin形式动态更改CultureInfo

  4. 4

    如何以Xamarin形式检测设备的大小

  5. 5

    如何以 xamarin 形式更改屏幕亮度

  6. 6

    如何以 xamarin 形式播放音频?

  7. 7

    如何以角度2的形式显示验证消息?

  8. 8

    如何以角度2的动态形式对验证消息进行反应

  9. 9

    如何以Rails形式动态使用Rowspan

  10. 10

    如何以选择形式使用if语句?

  11. 11

    如何以C ++形式使用TextBox文本?

  12. 12

    如何以Xamarin形式显示html格式的文本

  13. 13

    如何以xamarin形式调用同步Web服务调用?

  14. 14

    如何以Xamarin形式显示进度条通知

  15. 15

    如何以Xamarin形式获取Samsung Health计步表

  16. 16

    如何以Xamarin形式水平分布标签

  17. 17

    如何以Xamarin形式加入BLE通知中的值?

  18. 18

    如何以xamarin形式调用同步Web服务调用?

  19. 19

    如何以xamarin形式在xaml中进行动态设计

  20. 20

    您如何以非静态形式使用Q.all?

  21. 21

    如何以infix形式使用类型构造函数

  22. 22

    如何以ASP形式在MVC Core上使用datepicker

  23. 23

    如何以其他形式使用Ajax响应数据?

  24. 24

    您如何以非静态形式使用Q.all?

  25. 25

    如何以表格形式使用Spree身份验证

  26. 26

    在wtforms中如何以真实形式使用文档中的示例?

  27. 27

    如何以相同的形式使用来自输入标签的值

  28. 28

    如何以Twitter Bootstrap水平形式(在输入的右侧)正确地放置警告/错误消息?

  29. 29

    播放框架:如何以动态形式为特定字段设置错误消息

热门标签

归档