Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 30th, 2006, 12:45 AM
Thomas S
Guest
 
Posts: n/a
Default XML serialization via XmlWriter creates 3 weird bytes

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.To Array()).Replace(Environment.NewLine,
string.Empty));
}
}
}

Any idea why?

T


  #2  
Old July 30th, 2006, 05:55 AM
Thomas S
Guest
 
Posts: n/a
Default Re: XML serialization via XmlWriter creates 3 weird bytes

It had something to do with the MemoryStream, not sure what. It's working
now by writing from the XmlWriter directly to the StreamWriter.

"Thomas S" <thos37news@gmail.comwrote in message
news:u8sP2n2sGHA.4784@TK2MSFTNGP04.phx.gbl...
Quote:
>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.To Array()).Replace(Environment.NewLine,
string.Empty));
}
}
}
>
Any idea why?
>
T
>

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles