c# - 逐步在 ASP.Net Web API 上运行 swashbuckle

标签 c# wcf asp.net-mvc-3 asp.net-web-api swagger

我通过下载 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 MVC 5.x。在这种情况下,您必须将绑定(bind)重定向添加到您的 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/

相关文章:

c# - 避免将具体的数据库上下文类注入(inject) Controller

c# - 停止向外部发布到 Asp.Net WebForm 页面的能力

Jquery Ajax请求第二次未到达服务器

asp.net-mvc-3 - 如何在 Razor 页面上干净地设置 html 属性?

c# - 如何扩展 AuthorizeAttribute 并检查用户的角色

c# - RGB 宏 c# 等价物

c# - 对不同的 ChromeDriver 实例使用相同的 chrome 配置文件( session )

c# - 如何使用 WCF 在 WSSE 安全 header 中设置密码类型 "PasswordText"

c# - 尝试使用 WCF 服务时出现 FaultException

c# - 为什么 ASP.NET MVC 3 异常是 'handled' 两次?