简体   繁体   中英

Protobuf-net Attempting to JIT compile method '(wrapper dynamic-method) ClassExtensions.StringArray

Unity3d protobuf-net for serialization. I precompile my RuntimeTypeModel and then load it and use it for serializing.

On iOS I am still receiving the following error:

ExecutionEngineException: Attempting to JIT compile method '(wrapper dynamic-method) ClassExtensions.StringArray:proto_3 (object,ProtoBuf.ProtoWriter)' while running with --aot-only.

  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0 
  at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0 
  at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0 
  at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Compiler.CompilerContext.BuildSerializer (IProtoSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <filename unknown>:0 
Rethrow as InvalidOperationException: It was not possible to prepare a serializer for: ClassExtensions.StringArray
  at ProtoBuf.Compiler.CompilerContext.BuildSerializer (IProtoSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Serializers.CompiledSerializer..ctor (IProtoTypeSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Serializers.CompiledSerializer.Wrap (IProtoTypeSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Meta.MetaType.CompileInPlace () [0x00000] in <filename unknown>:0 
  at ProtoBuf.Meta.MetaType.get_Serializer () [0x00000] in <filename unknown>:0 
  at ProtoBuf.Meta.RuntimeTypeModel.Serialize (Int32 key, System.Object value, ProtoBuf.ProtoWriter dest) [0x00000] in <filename unknown>:0 
  at ProtoBuf.ProtoWriter.WriteObject (System.Object value, Int32 key, ProtoBuf.ProtoWriter writer) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Serializers.SubItemSerializer.ProtoBuf.Serializers.IProtoSerializer.Write (System.Object value, ProtoBuf.ProtoWriter dest) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Serializers.TagDecorator.Write (System.Object value, ProtoBuf.ProtoWriter dest) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Serializers.ListDecorator.Write (System.Object value, ProtoBuf.ProtoWriter dest) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Serializers.FieldDecorator.Write (System.Object value, ProtoBuf.ProtoWriter dest) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Serializers.TypeSerializer.Write (System.Object value, ProtoBuf.ProtoWriter dest) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Meta.RuntimeTypeModel.Serialize (Int32 key, System.Object value, ProtoBuf.ProtoWriter dest) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Meta.TypeModel.SerializeCore (ProtoBuf.ProtoWriter writer, System.Object value) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Meta.TypeModel.Serialize (System.IO.Stream dest, System.Object value, ProtoBuf.SerializationContext context) [0x00000] in <filename unknown>:0 
  at ProtoBuf.Meta.TypeModel.Serialize (System.IO.Stream dest, System.Object value) [0x00000] in <filename unknown>:0 
  at RouterConfig.Save (System.String configFileName) [0x00000] in <filename unknown>:0 
  at RouterConfig.SaveRun () [0x00000] in <filename unknown>:0 
  at Console.Update () [0x00000] in <filename unknown>:0 

Here is my class:

using ProtoBuf;

namespace ClassExtensions
{
    //this class will allow use to Serialize a List<StringArray>
    [ProtoContract]
    public class StringArray
    {
        [ProtoMember(1)] public string[] items { get; set; }
        public StringArray() {}
        public StringArray(string[] c) {this.items = c;}
        //conversion from string[] to StringArray 
        public static implicit operator StringArray(string[] a)
        { return new StringArray(a); }
        //conversion from StringArray to string[] 
        public static implicit operator string[](StringArray a)
        { return a.items; }
        //conversion from StringArray to string[] 


        public static string[][] ConvertToStringDoubleArray(List<StringArray> a)
        {
            List<string[]> b = new List<string[]>();
            foreach(StringArray c in a)
                b.Add(c.items);
            return b.ToArray();
        }
        //used to allow indexing...
        public string this[int i]
        {
            get { return this.items[i]; }
            set { this.items[i] = value; }
        }
    }
}

Compiling to DLL:

RuntimeTypeModel rModel = TypeModel.Create();

rModel.AllowParseableTypes = true;
rModel.AutoAddMissingTypes = true;

rModel.Add(typeof(StringArray), true);

rModel.Compile("MySerializer", "MySerializer.dll");

Based on my research this should be working. Am I missing something here?

Figured it out. The issue is although I precompiled it protobuf tried to compile again. Adding this line to the code fixes it.

rModel.AutoCompile = false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM