On a .NET 2.0 project I’m currently working on, where I’m getting my data from a webservice, I was getting the following error:
System.InvalidOperationException: Er is een fout opgetreden bij het genereren van het XML-document. ---> System.InvalidOperationException: Er is een kringverwijzing aangetroffen tijdens het toepassen van serialisatie op een object van het type BusinessObjects.Domein.
In English the error was:
System.InvalidOperationException: A circular reference was detected while serializing an object of type BusinessObjects.Domein.
I’ve found out that one of my objects must hold onto another object that is higher up in the chain which resulted into a circular reference. Yes indeed, this is true, but now it seems that xml serialization can’t handle it. My business object has a logical parent-child tree structure and that’s exactly how I want to have my business objects.
The only thing that can be done about it is by applying the [XmlIgnore] attribute to property that holds the reference to the parent object.
One big advantage is that there is less data sent over the wire when you invoke the webmethod. But since my business object is a plain old C# object (POCO), I’m not benefitting at all.
The biggest disadvantage, which I have to deal with in my situation is that unfortunately, these parent-child relationships will need to be repaired at the other end of the wire.
I’ve someone has a better solution please do react below this article.
Hope this is usefull!
gr,
Robbert