0

I have a list of properties, all are public and have getter and setter. But not all of them are serialized, few are missing. Can anyone tell me what could be the possible reason ?

//My class with public properties

public class student
{
public int id {get; set;};
public string fname {get; set;};
public string lname {get; set;};
}

//class where i include the above student class

[XmlInclude(typeof(student))]
public class event
{}

//Xml Serializer

XmlSerializer xmlSerializer = new XmlSerializer(event.GetType());
FileStream fileStream = File.Open(
filePathWithName,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.ReadWrite);
xmlSerializer.Serialize(fileStream, event);

var stringwriter = new System.IO.StringWriter();
var serializer = new XmlSerializer(event.GetType());
serializer.Serialize(stringwriter, event);

//xml file

<?xml version="1.0"?>
<Student>
<id>1</id>
<fname>abc</fname>
</Student>  

Now here the property lname is missing

  • this [question](http://stackoverflow.com/questions/575432/why-isnt-my-public-property-serialized-by-the-xmlserializer) might be of help. If not you could post some sample code... – Daniel J.G. Feb 27 '14 at 12:28
  • Bit more information / sample code would be nice. – Filip Cornelissen Feb 27 '14 at 12:39
  • It would have been nice some code that actually compiles and can be run. Are you missing string properties with null value? Then try setting `[XmlElement(IsNullable = true)]` on the string properties that you want to include when they are null – Daniel J.G. Mar 01 '14 at 10:14
  • thanks.. i was missing the string properties with null value. – user3360421 Mar 17 '14 at 05:59

0 Answers0