XmlWriter design flaws
I was very surprised to see an XmlException (hexadecimal value... is invalid character) when using a XmlReader on a XML file that was generated using a XmlTextWriter. It turned out that the method WriteString(String) does not check for some special characters and an invalid XML document might get generated. See details here.
The recommended workaround was subclassing XmlTextWriter and overriding WriteString() to handle this characters (remove or substitute the invalid characters). XmlTextWriter constructors accept parameters like Stream, TextWriter, but there is also a static factory method XmlWriter.Create(), which has overloads that accept an optional XmlWriterSettings parameter. The weird thing is that if no XmlWriterSettings is specified, then the Settings property of the XmlWriter is null and can not be instantiated, since it is readonly. This means that there is no way to create a subclass (e.g. SafeXmlTextWriter), with initialized Settings property. So, if the default settings are not applicable to your situation... well, tough luck, you can not apply the easy fix using the override:
public override void WriteString(String value)
{
value = FixInvalidCharacters(value);
base.WriteString(value);
}



