Nilesh Shah

Nilesh Shah

  • NA
  • 55.3k
  • 1.3m

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

Feb 15 2017 12:39 PM
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)