var bf = new BinaryFormatter(); var ms = new MemoryStream(); bf.Serialize(ms, ht); byte[] htobj = ms.ToArray();