Preview Knowledge Pack  devAdvantage

ISerializable Types Should be Marked Serializable

Classes that implement ISerializable must be marked with Serializable attribute.

Even though a class implements ISerializable the runtime will raise a SerializationException if any of the objects in the graph are not marked Serializable.  Therefore all classes that support the ISerializable interface should be marked Serializable with an attribute.

This rule violation can be automatically corrected with devAdvantage.

Example of class not marked Serializable (incorrect code)

[C#]
	public class BusinessStateObject : ISerializable
	{
		// Implementation
		public void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			// TODO:  Add BusinessStateObject.GetObjectData implementation

		}
	}
	

Example of class that fully implements ISerializable correctly

[C#]
	[Serializable]
	public class BusinessStateObject : ISerializable
	{
		// Implementation
		public void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			// TODO:  Add BusinessStateObject.GetObjectData implementation

		}
	}

See Also