Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find a circular reference during xml serialization?

I am trying to debug xml serialization. During xml serialization, the serializer "detected a circular reference". I'd like to find it and get rid of it. Is there some convenient tool / approach that I can use?

like image 214
MedicineMan Avatar asked Nov 05 '22 01:11

MedicineMan


1 Answers

Usually it is pretty obvious with manual inspection...

You might try serialising to a file, and just look at the end of the file - it won't be complete XML, obviously, but it should give a clue.

Note that DataContractSerializer is capable (by enabling an option) of serialising complete graphs, but it has less XML options than XmlSerializer has - and graph mode is even less XML-like; IMO removing the cycle is preferable. Usually this is just a case of something like:

[XmlIgnore]
public Person Parent {get;set;}

(i.e. serialize "downwards" references only)

like image 76
Marc Gravell Avatar answered Nov 14 '22 04:11

Marc Gravell