Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the metod 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?

like image 377
meJustAndrew Avatar asked Jan 13 '21 14:01

meJustAndrew


1 Answers

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
like image 60
Franz Gleichmann Avatar answered Sep 28 '22 11:09

Franz Gleichmann