I have a strange problem using XML Serializer. If the serialized object graph contains a string with a Form-Feed (0x0C) the serializer can serialize it properly, but it cannot deserialize the serialized representation.
Here is the proof of concept:
static void Main (string[] args)
{
var original = "test\fbla";
var stringBuilder = new StringBuilder ();
using (var writer = new StringWriter (stringBuilder))
{
new XmlSerializer (typeof (string)).Serialize (writer, original);
}
var serialized = stringBuilder.ToString ();
string deserialized;
using (var reader = new StringReader (serialized))
{
deserialized = (string) new XmlSerializer (typeof (string)).Deserialize (reader);
}
Console.WriteLine (deserialized);
}
The serialized string is:
<?xml version="1.0" encoding="utf-16"?>
<string>testbla</string>
The call to Deserialize
fails.
It seems that this is a bug in XmlSerializer
, since the serialized string seems to be well formed. Or am I doing something wrong?