In C#, how can I make XmlSerializer ignore a property during serialization but not during deserialization? (Or how do I do the same with Json.net?)
To prevent a prop
If you want to ignore the element at serialization with XmlSerializer, you can use XmlAttributeOverrides:
XmlAttributeOverrides overrides = new XmlAttributeOverrides();
XmlAttributes attribs = new XmlAttributes();
attribs.XmlIgnore = true;
attribs.XmlElements.Add(new XmlElementAttribute("YourElementName"));
overrides.Add(typeof(YourClass), "YourElementName", attribs);
XmlSerializer ser = new XmlSerializer(typeof(YourClass), overrides);
ser.Serialize(...