I am using .NET 3.5SP1 and DataContractSerializer
to serialize a class. In SP1, they changed the behavior so that you don\'t have to include DataContract
In XML Serializing, you can use the [XmlIgnore] attribute (System.Xml.Serialization.XmlIgnoreAttribute) to ignore a property when serializing a class.
This may be of use to you (Or it just may be of use to anyone who found this question when attempting to find out how to ignore a property when Serializing in XML, as I was).
What you are saying is in conflict with what it says in the MSDN library at this location:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx
I don't see any mention of the SP1 feature you mention.
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:
[DataContract]
, then remove the [DataMember]
for the property.[Serializable]
, then add [NonSerialized]
in front of the field for the property.[IgnoreDataMember]
to the property.Try marking the field with [NonSerialized()] attribute. This will tell the serializer to ignore the field.
https://msdn.microsoft.com/en-us/library/system.nonserializedattribute(v=vs.110).aspx
You might be looking for IgnoreDataMemberAttribute.