500 Error when setting up Swagger in asp .net CORE / MVC 6 app

I got this error when one of my functions was marked as public, but wasn't meant to be a web service which could be called directly.

Changing the function to private made the error go away.

Alternatively, immediately before your public function, you can put the [NonAction] command, to tell Swagger to ignore it.

[NonAction]
public async Task<IActionResult> SomeEvent(string id)
{ 
   ...
}

(I wish Swagger would actually report the name of the function which caused this problem though, rather than just complaining that it could no longer find the "../swagger/v1/swagger.json" file... that's not particularly useful.)


If someone want to know the exact error is in the Swagger's stack trace, request the URL:

<your-app-url>/swagger/v1/swagger.json

Or, click on the swagger.json link from the browser dev tools console:

Chrome DevTools with error log

Which will show the error in your IDE Output:

enter image description here


Initially I got a 500 error too. Deep down in the stacktrace it said: System.NotSupportedException: Unbounded HTTP verbs for path 'api/hotels'. Are you missing an HttpMethodAttribute?

It turned out I was missing a HttpGet attribute for one of my api methods:

[Microsoft.AspNetCore.Mvc.HttpGet]