XmlSerializer Utf-8 encoding

.net, c#, encoding, xml

Solution

Yes, by default `StreamWriter` is created for using UTF-8 without preamble. See details here

Problem

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?

Original source