MissingMethodException: Method not found: StaticFiles.StaticFileMiddleware..ctor
Issue Description
Swagger Open API documentation gives below error in .NET Core WebAPI after installing/migrating old .NET Core application to .NET Core 3.0.
System.MissingMethodException: ‘Method not found: ‘Void Microsoft.AspNetCore.StaticFiles.
System.MissingMethodException: 'Method not found: 'Void Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.. ctor(Microsoft.AspNetCore.Http.RequestDelegate,
Microsoft.AspNetCore.Hosting.IHostingEnvironment, Microsoft.Extensions.Options.IOptions`1,
Microsoft.Extensions.Logging.ILoggerFactory)'.
It is observed that Swagger API documentation/description doesn’t work as expected after upgrading to .NET Core 3.0.
The issue I found to be due to the incompatibility of existing swagger/swashbuckle packages with the latest .NET Core3.0 framework in the target app.
This issue is most observed with an application (using old swagger package) .NET Core 2.2 and lower version or may also exist with a 3.0 preview or lower version and then migrated to a new 3.0 version.
Resolution
I would recommend you to validate the swagger implementation with the below article,
Add Swagger API documentation to ASP.NET Core 3.0
Below is how I was able to fix the issue.
- Please uninstall any old version of Swagger / Swashbuckle packages.
- Please install below Swashbuckle Nuget package using package manager console,
PM> Install-Package Swashbuckle.AspNetCore -Version 5.0.0-rc4
(Please use latest available version )
Please see step by step on enabling Swagger(Open API) to.NET Core 3.0 web API.
Above package will install everything else required for swagger like,
- Swashbuckle.AspNetCore.SwaggerUI 5.0.0-rc4
- Swashbuckle.AspNetCore.Swagger 5.0.0-rc4
- Swashbuckle.AspNetCore.SwaggerGen 5.0.0-rc4
That’s all, You are all set with a fix, now you can run and test your swagger documentation.
Please make a note of a few breaking changes from .NET Core 2.2 to 3.0 in Swagger. I have detailed them in the article Swagger API Documentation in .NET Core 3.0.
You might be interested in,
Did the above steps resolve your issue? Please sound off in the comments below!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.
Thanks. I had this issue while migrating 2.1 services to .NET Core 3.0.
Thanks, Jassi. Glad it helped you. Above I had use RC version but now there is prod released latest version is available which can be used. Please see reference link above for more details