首页 > 解决方案 > Swagger 响应格式示例异常

问题描述

当我尝试在 swagger 帮助部分查看我的 api 时收到此错误消息。我需要添加什么来阻止此错误吗?

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.

标签: c#apiswagger

解决方案


GuidelineDataLayer.Model.Disease 是你自己的代码吗?您的对象中有一个循环引用,它阻止了模型序列化。再次检查您的代码,并确保您没有 2 个类相互指向。


推荐阅读