gpt4 book ai didi

c# - Protobuf-net 尝试 JIT 编译方法 '(wrapper dynamic-method) ClassExtensions.StringArray

转载 作者:行者123 更新时间:2023-11-29 10:42:10 31 4
gpt4 key购买 nike

用于序列化的 Unity3d protobuf-net。我预编译我的 RuntimeTypeModel,然后加载它并使用它进行序列化。

在 iOS 上我仍然收到以下错误:

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

这是我的类(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; }
}
}
}

编译为 DLL:

RuntimeTypeModel rModel = TypeModel.Create();

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

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

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

根据我的研究,这应该有效。我在这里遗漏了什么吗?

最佳答案

想通了。问题是虽然我预编译了它,但 protobuf 试图再次编译。将此行添加到代码中即可修复它。

rModel.AutoCompile = false;

关于c# - Protobuf-net 尝试 JIT 编译方法 '(wrapper dynamic-method) ClassExtensions.StringArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24015084/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com