I am trying to convert class to byte but not worked.
I receive a byte[] (b) with zero length . why ?
void start() { Item item = new Item(); item.files.Add(@"test"); byte[] b = ObjectToByteArray(item); // b will have zero length } [Serializable] public class Item : ISerializable { public Item() { files = new List<string>(); Exclude = false; CleanEmptyFolder = false; } public List<string> files; public string MusicProfileName; public bool Exclude; #region ISerializable Members public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("files", files); info.AddValue("MusicProfileName", MusicProfileName); info.AddValue("Exclude", Exclude); } #endregion } public byte[] ObjectToByteArray(object _Object) { using (var stream = new MemoryStream()) { // serialize object var formatter = new BinaryFormatter(); formatter.Serialize(stream, _Object); // get a byte array var bytes = new byte[stream.Length]; using (BinaryReader br = new BinaryReader(stream)) { bytes = br.ReadBytes(Convert.ToInt32(stream.Length)); } return bytes; } }