问题
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