I’m not sure how this piece of code works.
[Serializable]
class Blah
{
public Blah(int value)
{
this.value = value;
}
public int value;
}
BinaryFormatter b = new BinaryFormatter();
Blah blah = new Blah(4);
MemoryStream s = new MemoryStream();
b.Serialize(s, blah);
s.Seek(0, SeekOrigin.Begin);
blah = null;
blah = (Blah)b.Deserialize(s);
As I don’t have a parameterless constructor, it seems strange that the deserializer can create a new instance of Blah.
The deserialization process uses
FormatterServices.GetUninitializedObjectwhich gets an object without calling any constructor.