Possible Duplicate:
Why are “control” characters illegal in XML?
Saving an escape character 0x1b in an XML file
This throws an ArgumentException:
var c = '\x1A';
var xml = new XDocument(
new XDeclaration("1.0", "utf-8", null),
new XElement("test", new XCData(c.ToString()))
);
var foo = xml.ToString(); // ArgumentException
Why is .Net throwing this exception? I'm wrapping the illegal character in CDATA, so I would have thought that illegal characters would be handled for me. This is also the case for a bunch of other characters (e.g. 0x1B, 0x1C, 0x1E, 0x1E, 0x1F).
How do you work around this problem?