.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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -