我正在将 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>
我得到一个反射。发射错误:
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
注意。
我在不同的地方读到关闭“自动编译”可能是一种解决方法。这确实解决了我 nog 开始能够直接调用 Serialize - 所以看起来我不需要预编译的序列化程序。
在深入了解 protobuf 的内部工作原理后,我尝试这样做:
typeof(TypeModel).GetMethod("SetDefaultModel", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { new PDASerializers() })
但遗憾的是这也没有解决问题。
具体来说,我的问题如下;
是否可以替换默认序列化程序以使用 protobuf-net.grpc 中的预编译序列化程序,或者是否有其他方法可以全局关闭“自动编译” (对于 protobuf-net.grpc 也是如此)?