When should I mark a class as serializable with the [Serializable] attribute? The documention says that the class should not be inherited. However, I have used this attribute in conjuction with the XmlInclude attribute so I can serialize my derived classes as well. Is this incorrect?
I am using the XmlSerializer and StreamWriter classes to serialize my objects.
Also, my understanding tells me that any public properties (get and sets) will be serialized, other fields will be ignored. Is this also correct?
Any guidance would be appreciated.
Thanks
You never need the
[Serializable]attribute for XML serialization. It’s only used for serialization with formatters (e.g.BinaryFormatter,SoapFormatter)This is correct. Only public read/write properties are serialized, not fields.