Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherited members not (de)serialized properly #41

Closed
GoogleCodeExporter opened this issue Jul 1, 2015 · 6 comments
Closed

Inherited members not (de)serialized properly #41

GoogleCodeExporter opened this issue Jul 1, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

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

  • Changed state: Started
  • Added labels: Priority-High
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

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

  • Added labels: Priority-Medium
  • Removed labels: Priority-High

@GoogleCodeExporter
Copy link
Author

Detection and message added r228

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

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

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

  • Changed state: Verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant