I'm still playing with the newly released version of protobuf-net and I'm facing an issue I don't understand.
let's consider the piece of code 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 exception of type ProtoException
with the message "Possible recursion detected..."
The funny thing is that if I remove the attribute AsReference
on the Children
property it doesn't! Unfortunately, the lines above are just written to illustrate the problem and I need this attribute for the real structure I'm using.
So my question is... is it a known problem and is there any patch planned to fix it very soon? Or does anyone know any workaround?
Thanks