3
Answers

Serializing a class: "Serialize" or "DataContractAttribute"?

Nilesh Shah

Nilesh Shah

7y
378
1
What's the difference between using "Serialize" or "DataContractAttribute" while you want to make a class seriallizable?
 
Compiler warns: 
 
Type 'MyNAmeSpace.MyClass' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
 
Why doesno't it suggest using [Serialize] attribute?
 
P.S. the class is not used for any web service. It's a normal class which I want to write to DB.
 
Answers (3)