首页 文章

AspNet Core 2.0中的Ambiguites在Web API中使用Swagger

提问于
浏览
2

我试图在AspNet Core 2 Web API中使用Swagger . 我有一个基于以下工作的示例:

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

但是,当我尝试在另一个服务中使用相同的方法时,我得到编译错误:

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

以下方法或属性之间的调用不明确:'Microsoft.AspNetCore.Builder.SwaggerBuilderExtensions.UseSwagger(Microsoft.AspNetCore.Builder.IApplicationBuilder,System.Action)'

'Microsoft.AspNetCore.Builder.SwaggerBuilderExtensions.UseSwagger(Microsoft.AspNetCore.Builder.IApplicationBuilder,string,System.Action)'2>完成构建项目“SocialNetwork.Api.csproj” - 失败 .

目标调用位于Configure方法的Startup.cs中 .

// 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();
    }

有没有人对此有所了解?任何帮助将不胜感激 . 谢谢 .

2 回答

  • 2

    难道你有多个Swagger库的引用?在我的情况下,我不小心添加了对其他与swagger相关的Nuget包的引用,并且导致了与您描述的相同的错误 .

  • 1

    我卸载了Swagger并且刚刚安装了SwashBuckle.AspNetCore,因为它已经在里面实现了Swagger对象 . 这就是为什么它呼唤暧昧 .

相关问题