ISerializable
ISerializable is an interface defined in the .NET Framework that enables an object to control its own serialization and deserialization process. Implementing this interface allows a class to provide custom logic for converting its instance data into a serialized format and reconstructing an instance from that format. The interface resides in the System.Runtime.Serialization namespace and contains a single method: void GetObjectData(SerializationInfo info, StreamingContext context).
When a class implements ISerializable, the serialization infrastructure calls GetObjectData during serialization. Inside this method, the
Implementing ISerializable is often combined with the [Serializable] attribute. The attribute marks the type as eligible
Common use cases include handling complex object graphs, securing sensitive data by controlling what is exposed,
Care must be taken to maintain compatibility across versions. Changing the names of serialized values or the
Security concerns arise because deserialization can instantiate arbitrary types. Microsoft recommends avoiding BinaryFormatter with untrusted data
In summary, ISerializable gives a .NET developer fine‑grained control over the serialization pipeline, enabling custom data