Need to ignore property in XmlSerialization because of circular reference
- by NestorArturo
Have an object with a property I don't need to serialize. The type of this property generates a circular reference which I expected, so I decorated this property with everything comes to my mind:
private clsDeclaracion _Declaracion;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[System.Xml.Serialization.XmlIgnore]
public clsDeclaracion Declaracion
{
get { return _Declaracion; }
set { _Declaracion = value; }
}
However, the circular reference keeps firing. Tried using a public field with no luck.
This is my serialization code:
System.Xml.Serialization.XmlSerializer Serializador =
new System.Xml.Serialization.XmlSerializer(objeto.GetType());
using (StreamWriter SW = System.IO.File.CreateText(ArchivoTemp))
{
Serializador.Serialize(SW, objeto);
}