Hi,
When I serialize a object using the binaryformatter and save it to a file,
the file contains some parts of unreadable junk.
Should I do some encoding on the bytearray or something before saving it ?
All works fine when I use the soapformatter.
public byte[] Serialize(object o, SerializationFormat format) {
IFormatter iFor = null;
switch(format) {
case SerializationFormat.BINARY:
iFor = new BinaryFormatter();
break;
case SerializationFormat.SOAP:
iFor = new SoapFormatter();
break;
}
Stream mem = new MemoryStream();
iFor.Serialize(mem, o);
mem.Position = 0;
byte[] buffer = new byte[mem.Length];
mem.Read(buffer, 0, buffer.Length);
mem.Close();
return buffer;
}
----------
byte[] b = sl.Serialize(sett, SerializationFormat.BINARY);
//byte[] b = sl.Serialize(sett, SerializationFormat.SOAP);
FileStream fs = File.Open(p, FileMode.Open);
fs.Write(b, 0, b.Length);
fs.Close();
Thanks.