Xml Class Serialization Errors

PoosseNus

New Member
I am trying to create xml like this:\[code\]<CreditApplication> <ApplicantData> <FirstName> John </FirstName> <LastName> Smith </LastName> </ApplicantData> <CoApplicantData> <FirstName> Mary </FirstName> <LastName> Jane </LastName> </CoApplicantData></CreditApplication>\[/code\]And I've defined my classes as such:\[code\][XmlRoot("CreditApplication")]public class CreditApplication{ [XmlElement("ApplicantData")] public CreditApplicant Applicant; [XmlElement("CoApplicantData")] public CreditApplicant CoApplicant;}public class CreditApplicant : INotifyPropertyChanged{ ... [XmlElement("FirstName")] public string FirstName { set; get; } [XmlElement("LastName")] public string LastName { set; get; } ...}\[/code\]And further down in the CreditApplication class I have references to enumerations that are defined elsewhere in my program that also need to be made serilizable. When I actually run the program and try to serlizize the class with:\[code\]XmlSerializer applicantXMLSerializer = new XmlSerializer(typeof(CreditApplication));StringWriter applicantStringWriter = new StringWriter();XmlWriter applicantXmlWriter = XmlWriter.Create(applicantStringWriter);applicantXMLSerializer.Serialize(applicantXmlWriter, application);var applicantXML = applicantStringWriter.ToString();\[/code\]But I get the error: \[code\]There was an error reflecting type 'Models.Credit.CreditApplication'\[/code\]Does anyone have any idea what I'm doing wrong?EDIT:I've updated the above code to reflect the changes suggested. There are other issues that have presented themselves though. I have an enum defined as such:\[code\][DataContract]public enum Relationship{ Spouse = 4, ResidesWith = 1, Parent = 2, Other = 3, PersonalGuarantor = 5, CoApplicant = 6}\[/code\]As seen above, zero is not a defined option. Because of this, there is no default value. I have designed the program around the idea that a relationship that is not set defaults to zero. That way I can easily see if a value has been set. If I have zero defined and then have it initialize to "No Relationship" or something like that, then there is no way to tell if the user set the value to "No Relationship", or if they simply did not choose an option. Moved: XML Serialization of Enums Without Default Values
 
Back
Top