3

I have a class that doesn't seem to be working with protobuf-net serialization, and it seems to be breaking at the point that my class has a reference to another instance of itself. Here is an example (greatly simplified from my actual code):

[ProtoContract]
public sealed class Acorn
{
    [ProtoMember(50)]
    public string Investment;
    [ProtoMember(51)]
    public string Broker;
    [ProtoMember(52)]
    public Acorn DefaultTransferAcorn;
}

As far as I can tell, it is the reference to another Acorn class inside the Acorn class that appears to be causing the problem. I get the following error message in mono:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> ProtoBuf.ProtoException: Possible recursion detected (offset: 4 level(s)): AcornTrail3.Acorn

Is this a limitation of protobuf-net, or is there a way to make this work?

4

1 回答 1

5

By default protobuf is a "tree" structure. Protobuf-net adds graph support. Add AsReference=true to the ProtoMember affected.

于 2013-03-30T14:42:24.910 回答