System.Runtime.Serialization.OnDeserializingAttribute Class

When applied to a method, specifies that the method is called during deserialization of an object in an object graph. The order of deserialization relative to other objects in the graph is non-deterministic.

See Also: OnDeserializingAttribute Members


[System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)]
public sealed class OnDeserializingAttribute : Attribute


Use the System.Runtime.Serialization.OnDeserializingAttribute to set default values during deserialization. For example, if the type that you are deserializing does not contain a constructor, create a method to set values of any fields in the instance and apply the attribute to the method.

To use the System.Runtime.Serialization.OnDeserializingAttribute, the method must contain a System.Runtime.Serialization.StreamingContext parameter. The attribute marks the method to be called by the serialization infrastructure and the System.Runtime.Serialization.StreamingContext provides additional data about the type of serialization taking place. The usage is shown in the following code:

code reference: System.Runtime.Serialization.OnSerialization#4


In your code, you can use the word OnDeserializing instead of the longer System.Runtime.Serialization.OnDeserializingAttribute.


Namespace: System.Runtime.Serialization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions:,
Since: .NET 2.0