The following code;
var c = (char) 1;
var serializer = new XmlSerializer(typeof (string));
var writer = new StringWriter();
serializer.Serialize(writer, c.ToString());
var serialized = writer.ToString();
var dc = serializer.Deserialize(new StringReader(serialized));
Throws this exception in .NET 4.
Invalid Operation Exception – There is an error in XML document (2, 12). ”, hexadecimal value 0x01, is an invalid character. Line 2, position 12
Am I doing something wrong? Or is there a reasonable work around?
Many thanks!
There is a workaround as explained here – you can use
XmlReaderSettings.CheckCharactersoption to ignore validation of characters: