C# 具有简单继承结构的Protobuf net StackOverflowException

C# 具有简单继承结构的Protobuf net StackOverflowException,c#,protobuf-net,C#,Protobuf Net,我正在开发一个使用protobuf net将数据包写入流的系统,但我遇到了一个问题 我已成功地将有问题的代码提取为: 这将产生一个StackOverflowException,并使NUnit测试运行程序崩溃 在本例中,ChildBase是我的数据包的基类,RootType是protobuf-net保持不变所需的包装器实例 我是在做傻事吗 我是否必须向流中写入某种分隔符来分隔对象 在允许AsReference工作的同时,有没有更好的方法来写回不同类型的数据包 如果您有任何见解,我将不胜感激 以下

我正在开发一个使用protobuf net将数据包写入流的系统,但我遇到了一个问题

我已成功地将有问题的代码提取为:

这将产生一个
StackOverflowException
,并使NUnit测试运行程序崩溃

在本例中,
ChildBase
是我的数据包的基类,
RootType
是protobuf-net保持不变所需的包装器实例

  • 我是在做傻事吗
  • 我是否必须向流中写入某种分隔符来分隔对象
  • 在允许
    AsReference
    工作的同时,有没有更好的方法来写回不同类型的数据包
  • 如果您有任何见解,我将不胜感激

    以下是发生异常时堆栈的一部分,以供参考:

    protobuf-net.dll!ProtoBuf.Meta.RuntimeTypeModel.GetKey(System.Type type, bool demand, bool getBaseKey) Line 718 + 0xffffffd4 bytes  C#
    protobuf-net.dll!ProtoBuf.Meta.RuntimeTypeModel.GetKeyImpl(System.Type type) Line 711 + 0x10 bytes  C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.GetKey(ref System.Type type) Line 1224 + 0x10 bytes    C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.SerializeCore(ProtoBuf.ProtoWriter writer, object value) Line 183 + 0xc bytes  C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.Serialize(System.IO.Stream dest, object value, ProtoBuf.SerializationContext context) Line 218 C#
    protobuf-net.dll!ProtoBuf.ProtoReader.Merge(ProtoBuf.ProtoReader parent, object from, object to) Line 1337  C#
    [Lightweight Function]  
    protobuf-net.dll!ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read(object value, ProtoBuf.ProtoReader source) Line 57 + 0x1a bytes C#
    protobuf-net.dll!ProtoBuf.Meta.RuntimeTypeModel.Deserialize(int key, object value, ProtoBuf.ProtoReader source) Line 775 + 0xf bytes    C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.DeserializeCore(ProtoBuf.ProtoReader reader, System.Type type, object value, bool noAutoCreate) Line 700 + 0x14 bytes  C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.Deserialize(System.IO.Stream source, object value, System.Type type, ProtoBuf.SerializationContext context) Line 589 + 0x14 bytes  C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.Deserialize(System.IO.Stream source, object value, System.Type type) Line 566 + 0x14 bytes C#
    protobuf-net.dll!ProtoBuf.ProtoReader.Merge(ProtoBuf.ProtoReader parent, object from, object to) Line 1338 + 0x13 bytes C#
    [Lightweight Function]  
    protobuf-net.dll!ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read(object value, ProtoBuf.ProtoReader source) Line 57 + 0x1a bytes C#
    protobuf-net.dll!ProtoBuf.Meta.RuntimeTypeModel.Deserialize(int key, object value, ProtoBuf.ProtoReader source) Line 775 + 0xf bytes    C#
    ....
    

    请注意,我正在运行r668,因为我有.pdb,但最新版本也会产生溢出。

    oof;我需要找点时间把它分开-继承的总是很有趣的。。。表面上看起来不错,但是…谢谢你。这对我来说不是一个关键问题,因为我做了一个变通方法,确保输入流中只有一个
    RootType
    。不理想,但它可以工作。代码不再抛出
    StackOverflowException
    ;我需要找点时间把它分开-继承的总是很有趣的。。。表面上看起来不错,但是…谢谢你。这对我来说不是一个关键问题,因为我做了一个变通方法,确保输入流中只有一个
    RootType
    。不理想,但它可以工作。代码不再抛出
    StackOverflowException
    protobuf-net.dll!ProtoBuf.Meta.RuntimeTypeModel.GetKey(System.Type type, bool demand, bool getBaseKey) Line 718 + 0xffffffd4 bytes  C#
    protobuf-net.dll!ProtoBuf.Meta.RuntimeTypeModel.GetKeyImpl(System.Type type) Line 711 + 0x10 bytes  C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.GetKey(ref System.Type type) Line 1224 + 0x10 bytes    C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.SerializeCore(ProtoBuf.ProtoWriter writer, object value) Line 183 + 0xc bytes  C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.Serialize(System.IO.Stream dest, object value, ProtoBuf.SerializationContext context) Line 218 C#
    protobuf-net.dll!ProtoBuf.ProtoReader.Merge(ProtoBuf.ProtoReader parent, object from, object to) Line 1337  C#
    [Lightweight Function]  
    protobuf-net.dll!ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read(object value, ProtoBuf.ProtoReader source) Line 57 + 0x1a bytes C#
    protobuf-net.dll!ProtoBuf.Meta.RuntimeTypeModel.Deserialize(int key, object value, ProtoBuf.ProtoReader source) Line 775 + 0xf bytes    C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.DeserializeCore(ProtoBuf.ProtoReader reader, System.Type type, object value, bool noAutoCreate) Line 700 + 0x14 bytes  C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.Deserialize(System.IO.Stream source, object value, System.Type type, ProtoBuf.SerializationContext context) Line 589 + 0x14 bytes  C#
    protobuf-net.dll!ProtoBuf.Meta.TypeModel.Deserialize(System.IO.Stream source, object value, System.Type type) Line 566 + 0x14 bytes C#
    protobuf-net.dll!ProtoBuf.ProtoReader.Merge(ProtoBuf.ProtoReader parent, object from, object to) Line 1338 + 0x13 bytes C#
    [Lightweight Function]  
    protobuf-net.dll!ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read(object value, ProtoBuf.ProtoReader source) Line 57 + 0x1a bytes C#
    protobuf-net.dll!ProtoBuf.Meta.RuntimeTypeModel.Deserialize(int key, object value, ProtoBuf.ProtoReader source) Line 775 + 0xf bytes    C#
    ....