Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protobuf.net Unexpected subtype

I'm encountering this Exception in my project using Protobuf.net:

InvalidOperationException "Unexpected sub-type: foo"

I have a class which I'm sending which looks like this:

class message
{
    list<bar> listOfBars;
}

foo inherits off bar, However protobuf seems to choke on this and generate the exception above. Is there some way around this? I need to be able to hold all different subtypes of bar in the list, so a more type constrained solution would be difficult/impossible.

like image 489
Martin Avatar asked Sep 26 '10 11:09

Martin


1 Answers

I may be mistaken, but I think you need to specify on the inherited class which subtypes inherit from it, for example:

[Serializable, ProtoContract, ProtoInclude(100, typeof(Foo))]
class Bar { }

[Serializable, ProtoContract]
class Foo : Bar { } // Inherits from Bar
like image 136
djdd87 Avatar answered Oct 13 '22 04:10

djdd87