How can I ignore a property when serializing using the DataContractSerializer?
You might be looking for IgnoreDataMemberAttribute
.
Additionally, DataContractSerializer will serialize items marked as [Serializable] and will also serialize unmarked types in .NET 3.5 SP1 and later, to allow support for serializing anonymous types.
So, it depends on how you've decorated your class as to how to keep a member from serializing:
- If you used
[DataContract]
, then remove the[DataMember]
for the property. - If you used
[Serializable]
, then add[NonSerialized]
in front of the field for the property. - If you haven't decorated your class, then you should add
[IgnoreDataMember]
to the property.