I want to serialize an object via XmlWriter, but when I serialize to that, 3
strange bytes are added to the beginning of the output (0xEF, 0xBB, and
0xBF) all of which are in the ASCII range (ASCII 239, 187, 191)
public static void writeLogItem(LogItem ilog, string lfile)
{
lock (logLock)
{
using (StreamWriter outfile = new StreamWriter(lfile, true))
{
MemoryStream mstrm = new MemoryStream();
XmlSerializer writer = new
XmlSerializer(ilog.GetType());
XmlWriter xwrite = XmlWriter.Create(mstrm);
writer.Serialize(xwrite, ilog);
//writer.Serialize(mstrm, ilog);
outStatus("mstrm: " +
bytes2hex(mstrm.ToArray()).Substring(0,9) );
outfile.WriteLine(Encoding.UTF8.GetString(mstrm.ToArray()).Replace(Environment.NewLine,
string.Empty));
}
}
}
Any idea why?
T
Thomas S - 30 Jul 2006 06:01 GMT
It had something to do with the MemoryStream, not sure what. It's working
now by writing from the XmlWriter directly to the StreamWriter.
>I want to serialize an object via XmlWriter, but when I serialize to that,
>3 strange bytes are added to the beginning of the output (0xEF, 0xBB, and
[quoted text clipped - 25 lines]
>
> T