2017-11-03 1 views
0

SwaggerをAspNet Core 2 Web APIで使用しようとしています。Web APIのSwaggerを使用したAspNet Core 2.0のあいまいさ

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:

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

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

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

トンarget呼び出しは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(); 
    } 

これについての洞察はありますか?どんな助けでも大歓迎です。 ありがとうございます。

+0

拡張メソッドambigoiusで参照されている問題がトラップされているようです。使用方法を削除し、明示的に呼び出すようにしてください。たとえば、 'app.UseMvc();の代わりに' MvcApplicationBuilderExtensions.UseMvc(app); 'を使うことができます。 –

答えて

0

複数のSwaggerライブラリへの参照がある可能性はありますか?私のケースでは、誤って他のswaggerに関連するNugetパッケージへの参照を追加してしまったため、あなたが説明したのと同じエラーが発生しました。

0

Swaggerがアンインストールされていて、内部にSwaggerオブジェクトが既に実装されているため、SwashBuckle.AspNetCoreがインストールされました。それがなぜ曖昧になっているのでしょうか。

関連する問題