Search code examples
c#binary-deserialization

Binary deserialization: get object data


Is it possible to get data of the binary serialized object ( or list of othe same objects ) as it can be done in XML or soap. Please note, I have no idea about object structure ( private and public fields,etc)? By data of the binary serialized object I mean the values of all fields.


Solution

  • Lets say you have a stream.

                object yourData;
                var SerializeBinaryFileName = @"C:\Temp\binary.bf";
    
                using (Stream stream = File.Open(SerializeBinaryFileName, FileMode.Open))
                {
                    BinaryFormatter bformatter = new BinaryFormatter();
                    yourData = bformatter.Deserialize(stream);
                    stream.Close();
                }
    

    Then you have your object graph in the yourData variable. You can read it as any other object graph can be read.