.net - XMLSerialization in C# -
i have simple type explicitly implemets interface.
public interface imessageheader { string fromaddress { get; set; } string toaddress { get; set; } } [serializable] public class messageheader:imessageheader { private string from; private string to; [xmlattribute("from")] string imessageheade.fromaddress { { return this.from;} set { this.from = value;} } [xmlattribute("to")] string imessageheade.toaddress { { return this.to;} set { this.to = value;} } }
is there way serialize , deserialize objects of type imessageheader??
i got following error when tried
"cannot serialize interface imessageheader"
you cannot serialize imessageheader because can't activator.createinstance(typeof(imessageheader)) serialization going under covers. need concrete type.
you can typeof(messageheader) or say, have instance of messageheader ,
xmlserializer serializer = new xmlserializer(instance.gettype())
Comments
Post a Comment