0

I am getting this error message when I try to view my api in swagger help section. Is there something I need to add to stop this error?

Response Formats
application/json
Sample:
An exception has occurred while using the formatter 'JsonMediaTypeFormatter' to generate sample for media type 'application/json'. Exception message: Self referencing loop detected with type 'Model.Disease'. Path '[0].Types[0].List'.

text/json
Sample:
An exception has occurred while using the formatter 'JsonMediaTypeFormatter' to generate sample for media type 'text/json'. Exception message: Self referencing loop detected with type 'Disease'. Path '[0].Types[0].List'.

application/xml
Sample:
An exception has occurred while using the formatter 'XmlMediaTypeFormatter' to generate sample for media type 'application/xml'. Exception message: There was an error generating the XML document.

text/xml
Sample:
An exception has occurred while using the formatter 'XmlMediaTypeFormatter' to generate sample for media type 'text/xml'. Exception message: There was an error generating the XML document.

1 Answers1

2

GuidelineDataLayer.Model.Disease is your own code? You have a circular reference in your object that's preventing the model from serializing. Go over your code again and make sure you don't have 2 classes pointing at each other.

Zakk Diaz
  • 1,063
  • 10
  • 15
  • Here's a pretty good post about resolving it, it looks like swagger has a built in "allow" method for this kinda thing. https://stackoverflow.com/questions/17313632/self-referencing-loop-detected-getting-back-data-from-webapi-to-the-browser – Zakk Diaz Dec 17 '18 at 16:50
  • Sorry after looking again it looks like that method is specific to newtonsoft – Zakk Diaz Dec 17 '18 at 16:56
  • Yes I tried that and it worked text/json but not the xml –  Dec 17 '18 at 16:57