Reputation: 876
I am trying to use Swagger in an AspNet Core 2 Web API. I have one sample that works based on:
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.
Upvotes: 6
Views: 4582
Reputation: 51
I uninstalled Swagger and just installed the SwashBuckle.AspNetCore because it already implements the Swagger object inside. that is why it is calling ambigious.
Upvotes: 5
Reputation: 2809
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.
Upvotes: 2