public string Serialize(BackgroundJobInfo info)
{
var stringBuilder = new StringBuilder();
using (var stringWriter = new StringWriter(stringBuilder, CultureInfo.InvariantCulture))
{
var writer = XmlWriter.Create(stringWriter);
...
By default, StringWriter
will advertise itself as being in UTF-16
. Usually XML
is in UTF-8
.
So I can fix this by subclassing StringWriter
public class Utf8StringWriter : StringWriter
{
public override Encoding Encoding
{
get { return Encoding.UTF8; }
}
}
But why should I worry about that? What will be if I decide to use StringWriter
(like I did) instead of Utf8StringWriter
? Will I have some bug?
After that I will write this string to MongoDb