.NET Core 2 and SwashBuckle Swagger UI is not Displaying

谁说我不能喝 提交于 2019-12-04 03:36:16

What did the trick for me:

  1. Delete all old files from your deployment folder (I tried with IIS, also works for other hosting types)
  2. Replace all Microsoft.AspNetCore.* packages with Microsoft.AspNetCore.All meta package - see this post for the details.
  3. [optional] Just case of the side effects, reinstall Swashbuckle.AspNetCore package (no other Swashbuckle.AspNetCore.* packages needed)
  4. Make sure you have these 2 packages in the project file (it is enough to make it working):

    • PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0"
    • PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0"
  5. Publish (or deploy by copying the files) to your deployment folder. Now it should work.

NOTE: sometimes it fails (in this case it shows some unclear error in the browser) if you have duplicating model names in your API ;)

After downloading and testing your code, it appears you must add the following NuGet package to your project:

Microsoft.AspNetCore.StaticFiles

You can do this through the NuGet Manager or by adding the following line to your .csproj <ItemGroup>

<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" /> 

Source: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/438

Try deleting .vs folder. Fixed it for me after upgrading to ASP.NET Core 2.1

I had the same problem for several hours, but was using a port considered unsafe by Chrome (the text stating this was discreet and easy to miss). This may come in handy for somebody in the future.

I had same issue, I was missing HttpMethod binding.

System.NotSupportedException: Actions require an explicit HttpMethod binding for Swagger 2.0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!