You're missing the else
clause or return
statement in the setter. This will cause MyObject
to always be set to null
.
set
{
if (value.Length > 0)
{
IFormatter formatter = new BinaryFormatter();
using (var ms = new MemoryStream(value))
{
MyObject = formatter.Deserialize(ms);
}
return;
}
MyObject = null;
}
Reformatted for clarity:
set
{
if (0 >= value.Length)
{
MyObject = null;
return;
}
IFormatter formatter = new BinaryFormatter();
using (var ms = new MemoryStream(value))
{
MyObject = formatter.Deserialize(ms);
}
return;
}