Search code examples
c#asp.net-coreswagger

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.


Solution

  • 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" />