In WCF, how to inherit from a class that is not tagged DataContractAttribute or SerializableAttribute, and use this as a datacontract?
Example: I have a custom class called "EmailAttachment" that I inherited from System.Net.Mail.Attachment:
[DataContract] public class EmailAttachment : Attachment { [DataMember] public string AttachmentURL { set; get; } [DataMember] public string DisplayName { set; get; } }
But when I publish the service, it throws a runtime error, saying that:
System.Runtime.Serialization.InvalidDataContractException: Type 'EmailAttachment' cannot inherit from a type that is not marked with DataContractAttribute or SerializableAttribute.
What is the workaround for this?
Shyju source share