XmlSerializer Utf-8 encoding
23,833
Solution 1
Yes, by default StreamWriter
is created for using UTF-8 without preamble. See details here
Solution 2
Yes, the StreamWriter does default to UTF-8 as mentioned here
Author by
Patrick
Updated on November 21, 2020Comments
-
Patrick over 3 years
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?