1

Given an abstract base class:

[ProtoContract]
public abstract class UserSubmission : EntityObj
{
    [ProtoMember(51)]
    public int AuthorID { get; protected set; }
}

And an inheriting class:

[ProtoContract]
public partial class PrivateMessage : UserSubmission
{
    [ProtoMember(1000)]
    private int ToUserID { get; set; }

    ...

When I serialise/deserialise a PrivateMessage the AuthorID property is reset to default (0) when it should show a different value.

Am I doing anything wrong, or misunderstand how ProtoBuff.net works here?

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
  • you need to use `ProtoInclude` on the base class: `[ProtoInclude(999, typeof(PrivateMessage))]`. which seems backwards to me – Ňɏssa Pøngjǣrdenlarp Nov 04 '16 at 18:23
  • @Plutonix thanks for the answer, I have multiple inheritance and am playing round with what you suggest but am not sure exactly where to put `ProtoInclude`, on `EntityObj` or `UserSubmission`? Both seem to return `0` still. – Tom Gullen Nov 04 '16 at 18:35
  • [This answer has an article](http://stackoverflow.com/a/12989068/1070452) link which is interesting. If there is relevant Entiry stuff I *think* you'd have to include UserSubmission and PrivateMessage – Ňɏssa Pøngjǣrdenlarp Nov 04 '16 at 18:41
  • 1
    @Plutonix great thanks this works! I was getting confused as was defining all child classes in base class, when you should only protoinclude the direct children in each level. – Tom Gullen Nov 04 '16 at 18:45
  • @Plutonix if you want to put it into an answer happy to mark as correct! – Tom Gullen Nov 07 '16 at 14:13
  • Since there is already a good answer here (the link above), I'd just dupe-close to that. (I think I used that the first time *I* ran into the issue) – Ňɏssa Pøngjǣrdenlarp Nov 07 '16 at 14:35

0 Answers0