I was recently looking at Runtime Serialization and came across the ISerializationSurrogate
interface. I am confused about it's SetObject
method however.
The signature is:
object SetObjectData(object obj, System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.ISurrogateSelector selector)
and the help information is:
Summary:
Populates the object using the information in the System.Runtime.Serialization.SerializationInfo.
Parameters:
obj: The object to populate.
info: The information to populate the object.
context: The source from which the object is deserialized.
selector: The surrogate selector where the search for a compatible surrogate begins.
Returns:
The populated deserialized object.
If obj
is the object to populate, why does it return The populated deserialized object
? In one example from MSDN they populate obj
and return null
.
Check this .NET column article: http://msdn.microsoft.com/en-us/magazine/cc188950.aspx
It says:
Notice that the SetObjectData method has a return type of Object. This would make you think that SetObjectData could actually return a reference to a completely different type of object. However, the Microsoft SoapFormatter and BinaryFormatter types ignore this return value completely, which is why I returned null in the previous example. Obviously, there is a bug here; the return value should allow SetObjectData to return a different object.
Microsoft has scheduled this bug for repair. If the return value is null, then the formatter will use the object that it passed to SetObjectData. If SetObjectData returns an object reference, then the formatter will use the object that's returned. Unfortunately, until this bug is fixed, you can't deserialize a value type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With