4

If you look at the sources for System.Delegate you'll see that it implements ISerializable interface:

[Serializable, ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual),__DynamicallyInvokable]
public abstract class Delegate : ICloneable, ISerializable

but the actual implementation throws an exception:

public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
    throw new NotSupportedException();
}

Why is ISerializable used; are there any derived types that actually do use serialization?

rbm
  • 3,243
  • 2
  • 17
  • 28
  • http://referencesource.microsoft.com/mscorlib/R/81967491794ed15c.html – user4003407 Sep 08 '15 at 11:02
  • Binary serialization demands that the base class of a class that gets serialized is serializable as well. But you never *actually* serialize an object of type Delegate, it is an abstract class. You'll serialize a MulticastDelegate. Which has an implementation for GetObjectData(). – Hans Passant Sep 08 '15 at 11:05
  • understood about the `MulticaseDelegate`. Are you saying you can binary serialize a delegate (multicasedelegate)? – rbm Sep 08 '15 at 11:10
  • 1
    Just try it. Also the best way to find out why this is a feature that you should (almost) never use. – Hans Passant Sep 08 '15 at 11:26

0 Answers0