I'm trying to serialize a string with some escape characters (\0). But when I deserialise it throws an exception.
//XML serialization
private static void M1()
{
string str = "\0AC";
StringWriter sw = new StringWriter();
XmlSerializer serializer = new XmlSerializer(typeof(String));
serializer.Serialize(sw, str);
System.Console.WriteLine("String encoded to XML = \n{0} \n", sw.ToString());
StringReader sr = new StringReader(sw.ToString());
String s2 = (String)serializer.Deserialize(sr);
System.Console.WriteLine("String decoded from XML = \n {0}", s2);
}
//Using Binary serialization
void BinaryFormat1()
{
IFormatter bf = new BinaryFormatter();
string str = "\0MyName";
FileStream fs = new FileStream("SerilizedString.Data", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
bf.Serialize(fs, str);
fs.Close();
fs = new FileStream("SerilizedString.Data", FileMode.Open, FileAccess.Read, FileShare.None);
string data = (string)bf.Deserialize(fs);
fs.Close();
Console.WriteLine("data : " + data.ToString());
}