Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

services.AddSwaggerGen() giving error

All I'm trying to do is add swagger to an ASP.Net Core application. I'm watching a tutorial and all I see them do is add services.AddSwaggerGen(); under the configure services area in the Startup.cs file. Like any normal service like MVC... But I get an error:

There is no argument given that corresponds to the required formal parameter 'setupAction'...

I don't see anyone supplying any kind of argument to services.AddSwaggerGen() so does anyone know what I'm missing here?

I've added the SwashBuckler.AspNetCore dependency so swagger is in the application. Just don't know why it's red and giving the above error.

like image 873
Daniel Jackson Avatar asked Apr 30 '17 14:04

Daniel Jackson


People also ask

What is services AddSwaggerGen?

AddSwaggerGen is an extension method to add swagger services to the collection. To configure Swagger, you invoke the method SwaggerDoc. Passing an Info object, you can define the title, description, contact information, and more in code file Startup. cs.

How do I fix Swagger internal server error?

HTTP 500 (Internal Server Error) is a generalized error message. To get more specific details regarding those failures, please set logging level to "data" for that respective port under "Settings > Dynamic" on API Gateway Manager. Then, run the ReST call again and check the traffic log.

How do I enable Swagger in .NET core?

Add and configure Swagger middleware Launch the app and navigate to https://localhost:<port>/swagger/v1/swagger.json . The generated document describing the endpoints appears as shown in OpenAPI specification (openapi. json). The Swagger UI can be found at https://localhost:<port>/swagger .


1 Answers

I had problem, that

IServiceCollection does not contain a definition for 'AddSwaggerGen'

I turnes out, that I installed Swashbuckle.AspNetCore.Swagger nuget package instead of Swashbuckle.AspNetCore.

In .NET Core 3, there's some issues as discussed here. The solution is to add the following to the project file, replacing the prior version.

<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" /> <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc2" /> 
like image 122
Mik Avatar answered Oct 15 '22 01:10

Mik