Swagger UI Not Loading Sometimes

Viewed 1812

I'm using latest version of Swagger in my ASPNetCore 3.1 project and debugging on latest version of Chrome. When I try to enter swagger page it sometimes not loading and i see an empty page. It looks like totally random. It solves after I refresh the page.

I saw these errors on console.

GET https://localhost:44389/swagger/swagger-ui-bundle.js net::ERR_HTTP2_PROTOCOL_ERROR

index.html:95 Uncaught ReferenceError: SwaggerUIBundle is not defined
    at window.onload (index.html:95)

File in the error is random. Its sometimes a js file, sometimes a .css file. It changes.

If I publish this project on IIS and disable Http/2 support I never encounter this error.

Why?

2 Answers

You can try the following:

1.Check if all your controller methods have [http] tag. If they all do and still doesn't work go to step 2

2.In your configure function to ensure that you have app.UseStaticFiles(); If it still doesn't work go to step 3

3.Uninstall and reinstall swagger. If it doesn't work go to step 4 (Core Only)

4.If you are using Core Install Microsoft.AspNetCore.StaticFiles and reference it in your project.

I encountered the same problem, SwaggerUIBundle is not defined, and the problem is not on the web app that I'm developing but on my network. The problem was resolved after I switch to another network.

Related