开发者

exception while serializing a graph

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..."

开发者_如何学JAVA

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


This is simply a bug (thank you for exercising the beta so thoroughly!) - in the dynamic/reference handling it was double-counting the object (once as part of the shim wrapper it spoofs to do the magic, and once for the object itself).

For efficiency, the recursion detection only kicks into full gear beyond a specific depth. Your code tripped this depth, causing the double-counting to be seen as recursion. I have fixed this in the code. The code above passes locally, and will be in the next drop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜