I have problem with deserialization using protobuf-net.
I have the following class:
[ProtoContract]
public class CrazyList : List<string>
{
[ProtoMember(1)]
private readonly string _foo;
public CrazyList(string foo)
{
_foo = foo;
}
public CrazyList(){}
public new void Add(string item)
{
Console.Write(item + foo); // Problem is here!
base.Add(item);
}
}
And use it like this:
var list = new CrazyList("world!");
list.Add("Hello ");
using (var ms = new MemoryStream())
{
Serializer.Serialize(ms, list);
ms.Position = 0;
var listDS = Serializer.Deserialize<CrazyList>(ms);
listDS.Add("Goodbye ");
}
The method Add
is firing before the _foo
field deserialization is completed.
How I can solve this problem?