Problems Deserializing Nested Dynamic Types with ProtoBuf-Net

丶灬走出姿态 提交于 2019-12-07 09:10:08

问题


I am trying to deserialize an object that is wrapped in several layers of DynamicType = true, using ProtoBuf-Net r668.

Using an older version of ProtoBuf-Net (v1), it will deserialize without a problem. With the latest version, however, it fails with

ProtoBuf.ProtoException : Internal error; a key mismatch occurred

    [ProtoContract]
    private class A
    {
        [ProtoMember(1, DynamicType = true)]
        public object Body { get; set; }
    }
    [ProtoContract]
    private class B
    {
        [ProtoMember(1, DynamicType = true)]
        public object Body { get; set; }
    }
    [ProtoContract]
    private class C
    {
        [ProtoMember(1)]
        public string Name { get; set; }
    }

    [Test]
    public void Try_Serialize_Nested_DynamicTypes()
    {
        var obj = new A() {Body = new B() {Body = new C() {Name = "Brian"}}};
        var serializer = new ProtoBufSerializer();
        var results = serializer.Serialize(obj);
        var g = serializer.Deserialize<A>(results);
    }

来源:https://stackoverflow.com/questions/22512610/problems-deserializing-nested-dynamic-types-with-protobuf-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!