ANewGuyInTown
ANewGuyInTown

Reputation: 6437

Using protobuf-net with inheritance and interface

I have a proto contract as follows:

[ProtoContract]
public MyContract: ContractBase
{
   [ProtoMember(1)] 
   List<IMyDto> MyData
  {
      get;
     set;
  }
}

My IMyDto looks like this and its implemenation MyDto

[ProtoInclude(600, typeof(MyDto))]
public interface IMyDto
{
   int MyData
   {
    get;
    set;
   }
}
[ProtoContract]
public class MyDto :IMyDto
{
   [ProtoMember(1)]
   int MyData
   {
    get;
    set;
   }
}

Finally, my ContractBase looks like this:

[ProtoContract]
[ProtoInclude(500, typeof(MyContract))]
public class ContractBase
{
   [ProtoMember(501)]
   public string[] ErrorMessages
   {
     get;
     set;
   }
 }

When I make the web service call, I keep getting the following error:

It was not possible to prepare a serializer for: ContractBase ---> System.InvalidOperationException: No serializer defined for type: IMyDto

Please note that this is a simplified version of code for understanding the problem.

Please let me know what I'm doing wrong? Any help is much appreciated.

Thanks.

Upvotes: 1

Views: 1660

Answers (1)

FireAlkazar
FireAlkazar

Reputation: 1882

Mark IMyDto with [ProtoContract] attribute.
It worked for me, after I've done that.
Getting Started documentation says, it is necessary every type participating in serialization is marked so.

Upvotes: 2

Related Questions