Need to ignore property in XmlSerialization because of circular reference
Posted
by
NestorArturo
on Stack Overflow
See other posts from Stack Overflow
or by NestorArturo
Published on 2011-11-23T16:34:34Z
Indexed on
2011/11/24
17:51 UTC
Read the original article
Hit count: 151
xml-serialization
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);
}
© Stack Overflow or respective owner