asp.net Swashbuckle 集成导致“无法加载文件或程序集 'System.Web.Http,版本 = 4.0.0.0”

pet*_*erc 7 c# asp.net swagger asp.net-web-api2 swashbuckle

我希望使用 Swashbuckle 将 Swagger 添加到我的 asp.net REST 服务,如此处所述

我完成了所有步骤,由于我使用的是 Owin,所以我安装了SwashbuckleSwashbuckle.Corenugets。

但是,当我运行并导航到时,http://localhost/myapp/swagger出现以下错误。

Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Run Code Online (Sandbox Code Playgroud)

我有5.2.4.01这个 DLL 的版本,所以我添加了以下重定向

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="4.0.0.0" newVersion="5.2.4.0" />
  </dependentAssembly>

  <dependentAssembly>
    <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.2.4.0" />
  </dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

我还添加了System.Net.Http.Formatting重定向,因为我在另一篇文章中看到了这一点(但这没有什么区别)

我仍然收到如下错误...

    Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
    Running under executable  c:\windows\system32\inetsrv\w3wp.exe
    --- A detailed error log follows. 

    === Pre-bind state information ===
    LOG: DisplayName = System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
     (Fully-specified)
    LOG: Appbase = file:///D:/dev/myapp/trunk/myapp/
    LOG: Initial PrivatePath = D:\dev\myapp\trunk\myapp\bin
    Calling assembly : Swashbuckle.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd1bb07a5ac7c7bc.
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: D:\dev\myapp\trunk\myapp\web.config
    LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 5.2.3.0.
    LOG: Post-policy reference: System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/myappdev/0d9cef3e/aedd2787/System.Web.Http.DLL.
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/myappdev/0d9cef3e/aedd2787/System.Web.Http/System.Web.Http.DLL.
    LOG: Attempting download of new URL file:///D:/dev/myapp/trunk/myapp/bin/System.Web.Http.DLL.
    WRN: Comparing the assembly name resulted in the mismatch: Build Number
    ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Run Code Online (Sandbox Code Playgroud)

我可以看到它正在尝试使用重定向的文件,并且我已检查该文件是否在我的bin文件夹中,但是,如上所述,它仍然不起作用。

我有以下内容,包括我的packages.config...

      ...
      <package id="Microsoft.AspNet.Cors" version="5.2.4" targetFramework="net47" />
      <package id="Microsoft.AspNet.WebApi" version="5.2.4" targetFramework="net47" />
      <package id="Microsoft.AspNet.WebApi.Client" version="5.2.4" targetFramework="net47" />
      <package id="Microsoft.AspNet.WebApi.Core" version="5.2.4" targetFramework="net47" />
      <package id="Microsoft.AspNet.WebApi.Cors" version="5.2.4" targetFramework="net47" />
      <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.4" targetFramework="net47" />
      <package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.4" targetFramework="net47" />
      <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.4" targetFramework="net47" /> 
      ...
      <package id="Swashbuckle" version="5.6.0" targetFramework="net47" />
      <package id="Swashbuckle.Core" version="5.6.0" targetFramework="net47" />
      ...
      
Run Code Online (Sandbox Code Playgroud)

我在这里还能尝试什么?