I have a class which uses object serializer to serialize properties. The class is derived from another class as follows
[Serializable]
public class TargetInfo:
PropertyHandler
When I call the serialize method, serializer tries to serialize the PropertyHandler class as well and throws different exceptions since PropertyHandler class does not comply to the Serialization rules. How can I avoid serialization of PropertyHandler and serialize only TargetInfo?
You have a number of options... if you want to serialize a class that extends a base class, then that base class must also be marked with the
Serializable
attribute. You can however add theNonSerialized
attribute to members of the base class that you do not want to be serialized.If this is still not right for you, you can try some custom serialization by implementing the
ISerializable
interface, providing you with more control over exactly what is serialized. Please take a look at the Object Serialization in the .NET Framework page at MSDN for more help on this subject.