I am trying to convert an object say User having multiple fields into an XML. The problem is that I get an exception when it tries to serialize an ILIST member. Following is the code I am using:
var stringwriter = new System.IO.StringWriter();
var serializer = new XmlSerializer(User.GetType()); <!-- Getting exception here -->
serializer.Serialize(stringwriter, User);
return stringwriter.ToString();
My User looks something like this:
class User
{ public virtual string Name{ get; set; }
public virtual DateTime? LastUpdated { get; set; }
public virtual int? ContactId { get; set; }
public virtual IList<Sector> Sectors { get; set; }
public virtual AccessLevel AccessLevel { get; set; }
public virtual IList<UserRole> UserRole { get; set; }
}
Is there a way by which I can check if a member of the class whose object I am serializing is serializable or not and then tweak the logic for that particular member. I have less control over the user class. :( So any way where I could extend my code to handle IList members will be preferred.