I am using protobuf-net with protobuf-net.grpc and am attempting to get it to work on Xmarin/Ios.
Currently I have attempted to create a pre-compiled serializer:
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");
When i reference this .dll and do new PDASerializers().Serialize(new UserInfo())
it works without issues.
I am however walking into a brick wall when attempting to go all in into awesomeness and use protobuf-net.grpc
.
The issue is that as soon as I call: channel.CreateGrpcService<ISomeInterface>
I get a reflection.emit error:
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
nb.
I read at various places turning off "AutoCompile" could be a work around. This did solve me nog begin able to call Serialize directly - so it would seem I have no need for a pre-compiled serializer.
After some digging into the inner workings of protobuf I attempted to do this:
typeof(TypeModel).GetMethod("SetDefaultModel", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { new PDASerializers() })
But regretfully this also did not solve the issue.
Concretely my question is as follows;
Is it possible to either replace the default serializer to use the pre-compiled one in protobuf-net.grpc or is there some other way to turn off "AutoCompile" globally (so also for protobuf-net.grpc)?