UPDATE: Starting in Beta 13 and above, we recommend you to use the new DataContractSerializer instead of the XmlSerializer.



Please use the following code to serialize an object with the XmlSerializer:

var serializer = new XmlSerializer(typeof(ClassToSerialize));
var stream = new MemoryStream(); serializer.Serialize(stream, _classToSerialize);
stream.Seek(0, SeekOrigin.Begin);
var reader = new StreamReader(stream);
var serializedXml = reader.ReadToEnd();

Please use the following code to deserialize an object with the XmlSerializer:

var deserializer = new XmlSerializer(typeof(ClassToSerialize));
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(serializedXml));
var xmlReader = XmlReader.Create(memoryStream);
ClassToSerialize deserializedObject = (ClassToSerialize)deserializer.Deserialize(xmlReader);

Example of serializable class:

public class ClassToSerialize
    public string TextField { get; set; }
    public DateTime DateField { get; set; }
    public Guid GuidField { get; set; }
    public bool BooleanField { get; set; }


For any question, please post a message on the forums or contact us at support@cshtml5.com