500 Error when setting up Swagger in asp .net CORE / MVC 6 app
Solution 1:
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]
Solution 2:
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:
Which will show the error in your IDE Output:
Solution 3:
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.)
Solution 4:
Firstly you can enable de developer exception page by adding app.UseDeveloperExceptionPage();
on your Configure() in order to see better which is the root cause. Take a look here
In my case the problem was that I have to install also Microsoft.AspNetCore.StaticFiles
nuget in order to make Swagger work.
Try also to uninstall/reinstall Swashbuckle.AspNetCore
nuget.