Possible Duplicate:
Serializable Inheritance
Is serialization inheritable?
Example:
[Serializable]
class A
{
}
class B : A
{
}
If I try to serialize/deserialize an instance of class B, I get an exception stating that the class is not marked as serializable. Thus the question: is serialization inheritable? Am I just missing how to do it, or does every class that needs to be serialized require explicitly being marked as such?
It's not inheritable:
It is important to note that the Serializable attribute cannot be inherited. If you derive a new class from MyObject, the new class must be marked with the attribute as well, or it cannot be serialized.
You should mark the subclass as well to make it serializable:
[Serializable]
class B : A { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With