简体   繁体   中英

How to debug error 500 in Swashbuckle 5 for ASP.Net

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.

Swashbuckle UI 中的错误 500 没有响应数据的 Swagger 错误

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: swagger/docs/v1 错误响应标头

The problem is your URL request.change HTTPS to HTTP .

http://localhost:xxxx/...

You can NOT simulate HTTPS locally because SSL certificate doesn't exist in your local machine.

Update

i faced status 500 recently when RAM was saturated and there were not enough free memory

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.

Usually, I use Chrome Dev Tools to debug this kind of error. Also, you can get more information on Event Viewer if you are using Windows OS. Another option is checking the stacktrace from API's Swagger documentation site. For example api.domain.com/help/index or yourApiUrl/swagger/v1/swagger.json .

I've found a link could be helpful too: https://github.com/domaindrivendev/Swashbuckle/issues/969

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM