I am still playing with the recently released version of protobuf-net, and I ran into a problem that I do not understand.
consider the code snippet below:
[ProtoContract]
class Node
{
public Node()
{
Children = new List<Node>();
}
[ProtoMember(1, IsRequired = true)]
public int Data { get; set; }
[ProtoMember(2, IsRequired = true, AsReference = true)]
public List<Node> Children { get; set; }
public void AddChild(Node child)
{
Children.Add(child);
}
}
static void Main()
{
Node n = new Node {Data = 0}, root = n;
for (int i=1; i<15; i++)
{
Node child = new Node {Data = i};
n.AddChild(child);
n = child;
}
Node clone = Serializer.DeepClone(root);
}
It throws a type exception ProtoExceptionwith the message "Possible recursion detected ..."
The funny thing is that if I remove the attribute AsReferencein the property Children, it’s not! Unfortunately, the lines above are just written to illustrate the problem, and I need this attribute for the real structure that I use.
So my question is ... is this a known issue, and is there any patch that is planned to be fixed very soon? Or does anyone know of a workaround?
thank
source
share