C # Mono aot with protobuf-net getting ExecutionEngineException

First, many thanks to Mark Gravel of the author protobuf-net http://code.google.com/p/protobuf-net/ . This is a really great resource. Anyway, I hope that Mark or someone else can help me resolve this exception.

I am trying to implement protobuf-net on mobile devices (iOS and Android) using the Unity3D game engine. Unity 3.2 uses Mono 2.6, their slightly modified version of mono.

It works fine in the editor, but on the iOS device at runtime it fails in the first member that it tries to serialize. Note the -aot-only flag in the exception. I think Unity basically creates an ARM assembly through the Mono aot function, although I don’t understand what it does under the hood.

ExecutionEngineException: Attempting to JIT compile method 'ProtoBuf.Property.Property`2<GameManagerSaveState , bool>:.ctor ()' while running with --aot-only. at ProtoBuf.Property.PropertyBoolean`1[GameManagerSaveState]..ctor () [0x00000] in <filename unknown>:0 at ProtoBuf.Property.PropertyFactory.CreateProperty[GameManagerSaveState] (System.Type type, ProtoBuf.DataFormat& format, MemberSerializationOptions options) [0x00000] in <filename unknown>:0 at ProtoBuf.Property.PropertyFactory.Create[GameManagerSaveState] (System.Reflection.MemberInfo member) [0x00000] in <filename unknown>:0 at ProtoBuf.Serializer`1[GameManagerSaveState].Build () [0x00000] in <filename unknown>:0 

The IRC suggested that I could declare variables of these types in advance that the compiler would not need to JIT them at runtime. Sounds like a great idea, but unfortunately they look like internal generic types and don't know what to write in C # to declare variables, to fake the compiler. Can someone interpret the above message and tell me what the compiler should know in advance? Any other strategies to prevent this? BTW Here is the top of the class where the error

 using UnityEngine; using System; using System.Collections; using System.Collections.Generic; using ProtoBuf; [ProtoContract] public class GameManagerSaveState { [ProtoMember(1)] public bool gameOver; // snip 

Thanks to Mono and the proto-boof experts for helping me nail this one! protobuf-net seems to be an amazing and lightweight serialization protocol and RPC protocol that is perfect for iOS and Android applications, so I'm looking forward to using it.

+4
source share
2 answers

There are a number of issues in v1 that make it a little sick before JIT; v2, although incomplete, is intended to solve many / all of these problems, not least by offering the option of pre-compilation in dll, but even a run-only version should be much more device-friendly.

I should also mention that the Jon port of the Java version should work well here, as it is more a compiler than a heavy one.

+4
source

Use this before using protobuf:

 Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes"); 

Credit: https://github.com/antonholmquist/easy-serializer-unity

+1
source

Source: https://habr.com/ru/post/1341051/


All Articles