Consider the code below
XmlSerializer serializer = new XmlSerializer(typeof(Invoice));
using (TextWriter writer = new StreamWriter(fileName))
{
// Serialize the object, and close the TextWriter.
serializer.Serialize(writer, invoice);
writer.Close();
}
No encoding is set on the stream writer by default. Does it default to UTF-8 if you don't set an encoding on the stream writer?