I'm using the protobuf-net library to speed up wcf serialization and now I've come to a problem with derived classes. I looked into several discussions about class derivation but none fits my problem.
I'm using the following base:
[DataContract, ProtoContract]
//[ProtoInclude(10000, typeof(SysLoginRequest))]
public class ServiceRequest
{
public ServiceRequest()
{
// No parameterless constructor found for ServiceRequest?
RuntimeTypeModel.Default.Add(typeof(ServiceRequest), true).AddSubType(10000, typeof (SysLoginRequest));
}
}
And the derived class:
[DataContract, ProtoContract]
public class SysLoginRequest : ServiceRequest, IServiceRequest<SysLoginResponse>
{
[DataMember(Order = 1, IsRequired = true)]
public string UserSid { get; set; }
[DataMember(Order = 2, IsRequired = true)]
public string UserName { get; set; }
[DataMember(Order = 3, IsRequired = true)]
public string Password { get; set; }
[DataMember(Order = 4, IsRequired = true)]
public string IpAddress { get; set; }
[DataMember(Order = 5)]
public string ProcessName { get; set; }
[DataMember(Order = 6)]
public int ProcessId { get; set; }
}
What I'm trying to do is to get away from attributes by adding the subclasses at runtime but in my test I always get the runtime error that there is no parameterless constructor for the base class? I tried to make the constructor static but that didn't help either.
If I use the attribute (and remove the constructor) everything is fine, but if I do it using the RuntimeTypeModel I get the error message. What am I doing wrong here?