我通过下载Swashbuckle开始运行项目“ Swashbuckle.Dummy.SelfHost”。然后我转到浏览器并检查了program.cs类的主要功能中声明的URL。当我在浏览器中输入相同的URL(如``http:/ localhost:8090 / swagger'')时,出现以下错误。任何人都可以指导我逐步运行斜盘扣解决方案并对其进行测试。如果我想将此应用程序托管在IIS上并运行,我需要遵循哪些步骤?

An error has occurred.

Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

System.IO.FileLoadException

at Swashbuckle.Application.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.HttpServer.<>n__FabricatedMethod9(HttpRequestMessage , CancellationToken ) at System.Web.Http.HttpServer.d__0.MoveNext()

最佳答案

问题是Swashbuckle在版本4中使用System.Web.Http和System.Net.Http.Formatting程序集。我假设您的应用程序正在使用ASP MVC5.x。在这种情况下,您必须将绑定重定向添加到您的web.config中。
将以下部分添加到您的web.config中(交换“ 5.0.0.0”以及您的应用程序实际引用的提到的程序集的版本):

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
        </dependentAssembly>
    </assemblyBinding>
  </runtime>

关于c# - 逐步在ASP.Net Web API上运行swashbuckle,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25407672/

10-10 07:40