Search code examples
c#swaggerasp.net-core-3.1swashbuckle.aspnetcore

Why the method app.UseSwaggerUI(...) is not found?


I want to add swagger on a new web application created with .NET Core 3.1. I receive an error on the following line:

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});

'IApplicationBuilder' does not contain a definition for 'UseSwaggerUI' and no accessible extension method 'UseSwaggerUI' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

even though I have installed Swagger as in the MSDN example.

This is the content of swagger package that came from NuGet:

enter image description here

I have the following usings:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;

What am I missing?


Solution

  • The NuGeT-package Swashbuckle.AspNetCore.Swagger only provides the JSON-endpoints of the documentation.

    To actually have the UI as well, you must also install the corresponding package Swashbuckle.AspNetCore.SwaggerUi

    Install-Package Swashbuckle.AspNetCore.SwaggerUi -Version 5.6.3