【发布时间】:2020-06-24 11:07:32
【问题描述】:
我正在将 protobuf-net 与 protobuf-net.grpc 一起使用,并试图让它在 Xmarin/Ios 上工作。
目前我正在尝试创建一个预编译的序列化程序:
RuntimeTypeModel runtimeTypeModel = RuntimeTypeModel.Create();
runtimeTypeModel.AllowParseableTypes = true;
runtimeTypeModel.AutoAddMissingTypes = true;
runtimeTypeModel.AutoCompile = false;
runtimeTypeModel.Add(typeof(UserInfo), true);
Directory.SetCurrentDirectory(@"..\..\");
runtimeTypeModel.Compile("PDASerializers", @"PDASerializers.dll");
当我引用这个 .dll 并执行 new PDASerializers().Serialize(new UserInfo()) 时,它可以正常工作。
然而,当我试图全力以赴并使用 protobuf-net.grpc 时,我正在走进一堵砖墙。
问题是,只要我打电话:channel.CreateGrpcService<ISomeInterface>,我就会收到一个反射.emit 错误:
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 ProtoBuf.Grpc.Internal.ProxyEmitter..cctor () [0x0001e] in /_/src/protobuf-net.Grpc/Internal/ProxyEmitter.cs:18
注意
我在不同的地方读到关闭“自动编译”可能是一种解决方法。这确实解决了我无法直接调用 Serialize 的问题 - 所以看起来我不需要预编译的序列化程序。
在深入了解 protobuf 的内部工作原理后,我尝试这样做:
typeof(TypeModel).GetMethod("SetDefaultModel", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { new PDASerializers() })
但是很遗憾这也没有解决问题。
具体我的问题如下;
是否可以替换默认序列化程序以使用 protobuf-net.grpc 中的预编译序列化程序,或者是否有其他方法可以关闭“自动编译”全局(也适用于 protobuf -net.grpc)?
【问题讨论】:
标签: protobuf-net protobuf-net.grpc