Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular reference in web service

I'm trying to resolve a circular reference in a web service. The solution builds fine and some operations are callable, but one which uses a referenced type gives a circular reference exception (below).

System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: A circular reference was detected while serializing an object of type MyCoreAssembly.MyType <-------- this is the referenced type
   at System.Xml.Serialization.XmlSerializationWriter.WriteStartElement(String name, String ns, Object o, Boolean writePrefixed, XmlSerializerNamespaces xmlns)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write21_VRD(String n, String ns, VRD o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write21_VRD(String n, String ns, VRD o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write31_Hereditament(String n, String ns, Hereditament o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write32_HereditamentVrd(String n, String ns, HereditamentVrd o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write33_VRDResponse(String n, String ns, VRDResponse o, Boolean isNullable, Boolean needType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write43_VRDResponse(Object o)
   at Microsoft.Xml.Serialization.GeneratedAssembly.VRDResponseSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)  <------- this is my type
   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
   at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
   at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
   at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
   at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
   at System.Web.Services.Protocols.WebServiceHandler.Invoke()

The architecture looks roughly like this:

Core layer <------ Data Layer <----- Logic Layer <---------- Web service
                     \/--------------------\/ <-------------------|
                                            \/--------------------|

Each layer is a separate assembly and the web service references all three assemblies. I've attached a debugger but it doesn't break. It looks like the internals are failing but I have no idea where as everything builds. How would I go about debugging this?

like image 263
Echilon Avatar asked Oct 09 '22 18:10

Echilon


1 Answers

Your circular reference is not in the project files, but in the objects you try to send over the webservice. One of you object has a reference to itself or an object that references to the object.

The error message tell you to look in your type: MyCoreAssembly.MyType

like image 136
Peter Avatar answered Oct 13 '22 12:10

Peter