To binary deserialize a custom object in C#, use following code snippet
private object BinaryDeSerializeAnObject(Stream stream)
{
object obj = null;
// Construct a binary formatter
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
// Deserialize the stream into object
obj = formatter.Deserialize(stream);
return obj;
}
Call above method like
BinaryDeSerializeAnObject(myCustomObjectInStream);
Thanks