title: Circular reference in web service
body: <p>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).</p>
  
  <pre><code>System.InvalidOperationException: There was an error generating the XML document. ---&gt; System.InvalidOperationException: A circular reference was detected while serializing an object of type MyCoreAssembly.MyType &lt;-------- 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)  &lt;------- 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()
  </code></pre>
  
  <p>The architecture looks roughly like this:</p>
  
  <pre><code>Core layer &lt;------ Data Layer &lt;----- Logic Layer &lt;---------- Web service
                       \/--------------------\/ &lt;-------------------|
                                              \/--------------------|
  </code></pre>
  
  <p>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?</p>