Multiple object references when deserializing with ProtoBuf even when using AsReferenceDefault

Viewed 147

We are migrating to ProtoBuf serialization and I look forward to use it.

I noticed that an object is deserialized multiple time, event if the classes referencing it are using AsReferenceDefault ([ProtoContract(AsReferenceDefault = true)]).

If the ProtoMember itself is declared with AsReference ([ProtoMember(1, AsReference = true)]), then the object is deserialized once. In my understanding, this would not be necessary because the ProtoContract is declared with AsReferenceDefault = true, but it seems that I'm wrong.

[ProtoContract(AsReferenceDefault = true)]
public class Card
{
    [ProtoMember(1, AsReference = true)] 
    //[ProtoMember(1)]
    public ItemCollection<ProcessingBlock> ProcessingBlocks { get; set; }
}

[ProtoContract(AsReferenceDefault = true)]
public class AnotherClass
{
    [ProtoMember(1, AsReference = true)]
    public DynamicProcessingBlock ProcessingBlock { get; set; }
}

[ProtoContract(AsReferenceDefault = true)]
public class DynamicProcessingBlock : ProcessingBlock
{
}

In the class Card, if I use the commented line, the DynamicProcessingBlock instance which is also referenced in AnotherClass is deserialized twice.

What is the real meaning of AsReferenceDefault = true on the ProtoContrat ?

Thank you very much

0 Answers
Related