Поделиться через


Steps in the serialization process

When the Serialize method is called on a formatter, object serialization proceeds according to the following sequence of rules:

  • A check is made to determine whether the formatter has a surrogate selector. If the formatter does, check whether the surrogate selector handles objects of the given type. If the selector handles the object type, ISerializable.GetObjectData is called on the surrogate selector.

  • If there is no surrogate selector or if it does not handle the object type, a check is made to determine whether the object is marked with the Serializable attribute. If the object is not, a SerializationException is thrown.

  • If the object is marked appropriately, check whether the object implements the ISerializable interface. If the object does, GetObjectData is called on the object.

  • If the object does not implement ISerializable, the default serialization policy is used, serializing all fields not marked as NonSerialized.

Warning

Binary serialization can be dangerous. For more information, see BinaryFormatter security guide.