如何在Swashbuckle 5中为ASP.Net调试错误500 [英] How to debug error 500 in Swashbuckle 5 for ASP.Net

查看:55
本文介绍了如何在Swashbuckle 5中为ASP.Net调试错误500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Swashbuckle/Swagger得到了500错误,这与

我通过反复试验对控制器和操作进行注释来手动跟踪问题端点,直到隔离出不良的端点为止,但这很慢,并且没有告诉我为什么,某些端点具有问题.我该怎么做才能获得有关Swagger/Swashbuckle错误的有意义的调试信息?

我在ASP.Net 4.6.2 WebApi应用程序中使用Swashbuckle 5.6.0和Swashbuckle.Core 5.6.0.唯一的配置在SwaggerConfig.cs文件中,如下所示.

 公共类SwaggerConfig{公共静态无效Register(){GlobalConfiguration.Configuration.EnableSwagger(c =>{c.SingleApiVersion("v1","My.Namespace.Here.WebApi");}).EnableSwaggerUi(c =>{});}} 

swagger/docs/v1 返回以下内容的500响应:

解决方案

我遇到了同样的问题,无法弄清原因.我的端点都工作正常,没有一个将EntityFramework中的实体作为参数或子属性.

但是我实际上有一个公共方法"public async MyAction(MyEntityentity)",它不是由API而是由内部机器人使用的.

我使用了标签 [ApiExplorerSettings(IgnoreApi = true)] 来忽略它,并且它通过了.

我当时使用的是自定义过滤器,以删除不需要的端点(我没有使用自定义属性标记的端点),但是由于过滤是由Swagger在以后的阶段完成的,因此没有到达我的过滤器,我得到了内存不足异常.

I'm getting an error 500 back from Swashbuckle/Swagger, and contrary to the best related answer I could find, I'm not seeing any additional information in the error response.

I manually tracked down the problem endpoints by trial-and-error commenting out controllers and actions until I isolated the bad ones, but this is slow and doesn't tell me why certain endpoints have a problem. What can I do to get meaningful debug information for the Swagger/Swashbuckle errors?

I'm using Swashbuckle 5.6.0 and Swashbuckle.Core 5.6.0 in an ASP.Net 4.6.2 WebApi app. The only configuration is in a SwaggerConfig.cs file, seen below..

public class SwaggerConfig
{
    public static void Register()
    {
        GlobalConfiguration.Configuration
            .EnableSwagger(c =>
                {
                    c.SingleApiVersion("v1", "My.Namespace.Here.WebApi");
                })
            .EnableSwaggerUi(c =>
                {
                });
    }
}

The swagger/docs/v1 returns a 500 response with the following:

解决方案

I had the same issue and couldn't figure out why. My endpoints were all working fine and none of them had Entities from EntityFramework as parameters or sub properties.

But I actually had a public method "public async MyAction(MyEntity entity)" which wasn't used as an API but by an internal bot.

I used the tag [ApiExplorerSettings(IgnoreApi = true)] to ignore it and it went through.

I was using a custom filter to remove un wanted endpoints (the ones that I hadn't flagged with a custom attribute) but since the filtering is done at a later stage by Swagger it didn't reach my filter and I got the out of memory exception before.

这篇关于如何在Swashbuckle 5中为ASP.Net调试错误500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆