Observe the following trivial code snippet:
[ProtoContract]
public class B
{
[ProtoMember(1)] public int Y;
}
[ProtoContract]
public class C
{
[ProtoMember(1)] public int Y;
}
class Program
{
static void Main()
{
var b = new B { Y = 2 };
var c = new C { Y = 4 };
using (var ms = new MemoryStream())
{
Serializer.Serialize(ms, b);
Serializer.Serialize(ms, c);
ms.Position = 0;
var b2 = Serializer.Deserialize<B>(ms);
Debug.Assert(b.Y == b2.Y);
var c2 = Serializer.Deserialize<C>(ms);
Debug.Assert(c.Y == c2.Y);
}
}
}
The first statement fails! Each Serialize statement advances the position of the stream by 2, so at the end of ms.Position it is 4. However, after the first Deserialize statement, the position is set to 4, not 2! In fact, b2.Y is 4, which should be the value of c2.Y!
There is something absolutely basic that I'm missing here. I am using protobuf-net v2 r383.
Thank.
EDIT
It must be something really stupid, because it doesn't work in v1 either.
source
share