tonynhan / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Inherited members not (de)serialized properly #41

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi! I'm currently struggling with inheritance in protobuf-net. I have the
following example:
[ProtoContract]
[ProtoInclude (2, typeof (B))]
public class A
{
    [ProtoMember (1, Name = "PropA")]
    public string PropA { get; set; }

    [ProtoMember (2, Name = "PropB")]
    public string PropB { get; set; }
}

[ProtoContract]
public class B : A
{
    [ProtoMember (1, Name = "PropAB")]
    public string PropAB { get; set; }
    [ProtoMember (2, Name = "PropBB")]
    public string PropBB { get; set; }
}

Now doing:
B b = new B {PropA = "a", PropB = "b", PropAB = "ab", PropBB = "bb"};
using (var s = new MemoryStream ())
{
   Serializer.Serialize (s, b);
   s.Position = 0;
   B bb = Serializer.Deserialize<B> (s);
   Console.WriteLine ("{0},{1},{2},{3}", bb.PropA, bb.PropB, bb.PropAB,
bb.PropBB);
}

Should produce: a,b,ab,bb
Instead I get: ,,ab,bb

So it seems like inherited members are not retrieved.

Original issue reported on code.google.com by maciej.p...@gmail.com on 11 Feb 2009 at 3:09

GoogleCodeExporter commented 9 years ago
Which build? Note that 225 fixed a bug in inherited properties. I'm trying the 
provided code now...

Original comment by marc.gravell on 11 Feb 2009 at 3:35

GoogleCodeExporter commented 9 years ago
Can reproduce on 225 - damn, thought I'd fixed that... will investigate ASAP.

Original comment by marc.gravell on 11 Feb 2009 at 3:44

GoogleCodeExporter commented 9 years ago
Update - the core code is fine - just change the ProtoInclude to tag **3** (it 
must 
not conflict with the properties). I'll investigate why it didn't raise a 
suitable 
error (it does for other conflicts).

Original comment by marc.gravell on 11 Feb 2009 at 3:50

GoogleCodeExporter commented 9 years ago
Detection and message added r228

Original comment by marc.gravell on 11 Feb 2009 at 4:04

GoogleCodeExporter commented 9 years ago
Thanks! Works like a charm. I didn't know actually what "tag" in ProtoInclude 
meant :)

Original comment by maciej.p...@gmail.com on 11 Feb 2009 at 4:44

GoogleCodeExporter commented 9 years ago
Indeed - I need to improve the documentation; time is my enemy... issue 42 will 
bbe a 
better man page ;-p

Original comment by marc.gravell on 11 Feb 2009 at 8:04