Ambiguites in AspNet Core 2.0 using Swagger in Web API

Viewed 2908

I am trying to use Swagger in an AspNet Core 2 Web API. I have one sample that works based on:

https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?tabs=visual-studio

However, when I try to use the same approach in another service I get compile error:

2>Startup.cs(41,17,41,27): error CS0121:

The call is ambiguous between the following methods or properties: 'Microsoft.AspNetCore.Builder.SwaggerBuilderExtensions.UseSwagger(Microsoft.AspNetCore.Builder.IApplicationBuilder, System.Action)'

and

'Microsoft.AspNetCore.Builder.SwaggerBuilderExtensions.UseSwagger(Microsoft.AspNetCore.Builder.IApplicationBuilder, string, System.Action)'

2>Done building project "SocialNetwork.Api.csproj" -- FAILED.

The target call is in Startup.cs in the Configure method.

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        // Enable middleware to serve generated Swagger as a JSON endpoint.
        app.UseSwagger(); // Ambiguous

        // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "SocialNetwork API V1");
        });

        app.UseMvc();
    }

Does anyone have insight on this? Any help would be greatly appreciated. Thank you.

3 Answers

I uninstalled Swagger and just installed the SwashBuckle.AspNetCore because it already implements the Swagger object inside. that is why it is calling ambigious.

Could it be that you have references to multiple Swagger-libraries? In my case I had accidentally added a reference to other swagger-related Nuget packages, and that caused the same error as you described.

Just uninstall the Swagger nugget package and you should be fine

Related