4

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?

Helen
  • 87,344
  • 17
  • 243
  • 314
Trax
  • 943
  • 2
  • 12
  • 30
  • Check the answers in this Q&A to see if they help: [What's the net::ERR_HTTP2_PROTOCOL_ERROR about?](https://stackoverflow.com/q/58215104/113116) – Helen Jun 16 '21 at 21:18
  • 1
    @Helen Unfortunately I've already tried all of these, nothing fixed : ( – Trax Jun 17 '21 at 07:22

2 Answers2

0

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.

Tupac
  • 2,590
  • 2
  • 6
  • 19
  • Unfortunately I've already tried all of these, nothing fixed : ( – Trax Jun 17 '21 at 06:56
  • Please check if swagger-ui-bundle.js is loaded. It is usually the case then the server is wrong configured and js files are not loaded – Tupac Jun 18 '21 at 07:24
  • I already checked everything. When I continuously refresh swagger-UI page it sometimes loads without any problem, but sometimes it gives "net::ERR_HTTP2_PROTOCOL_ERROR" on random .js and .css files. Strange thing is why this problem disappear if I disable HTTP/2 from IIS settings? – Trax Jun 20 '21 at 15:55
  • Does it work with Edge/Firefox browser?This article can be helpful to you:https://stackoverflow.com/questions/58215104/whats-the-neterr-http2-protocol-error-about – Tupac Jun 21 '21 at 09:07
  • Yes, it is also happening in other browsers. Only solution I found is disabling http/2 or uninstalling KB5004476 Windows Update. Maybe it's a bug about OS. – Trax Jun 22 '21 at 11:47
0

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.

sareno
  • 576
  • 8
  • 10