Is serializable attribute needed in concrete C# class?
Asked Answered
S

2

11

In C#, consider we have a generic class and a concrete class

[Serializable]
public class GenericUser
{ ...

[Serializable]
public class ConcreteUser : GenericUser
{ ...

is it necessary to mark ConcreteUser as [Serializable] or inheritance will take care of it?

Swimming answered 15/11, 2010 at 12:50 Comment(0)
U
6

Inherited is set to false with the [AttributeUsage] of SerializableAttribute, so yes, you need to set it on the concrete class.

See http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx for more information.

Unparalleled answered 15/11, 2010 at 12:52 Comment(0)
S
1

you need to mark both, if both are to be binary serialized.

Schlosser answered 15/11, 2010 at 12:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.