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

时间:2019-01-21 00:44:35

标签: c# asp.net asp.net-web-api2 swagger swashbuckle

我希望使用here中所述的Swashbuckle将Swagger添加到我的asp.net REST服务中。

我经历了所有步骤,并且由于我使用的是Owin,所以我同时安装了SwashbuckleSwashbuckle.Core nuget。

但是,当我跑步并导航至http://localhost/myapp/swagger时,出现以下错误。

Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

我具有此DLL的版本5.2.4.01,因此我添加了以下重定向

  <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>

我还添加了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.

我可以看到它正在尝试使用重定向的文件,并且我已经检查了该文件在我的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" />
      ...

有人对我还能在这里尝试什么有任何建议吗?

谢谢!

0 个答案:

没有答案