26

我刚刚将一个 Asp.Net Web Api 2.2 项目上传到生产服务器,我得到了标题中所述的错误。

在我的 Web.config 中,我已经有了这个:

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

该文件确实存在于 bin 中。什么会导致这个?
我所有的 Asp.Net Web API 文件都是最新的,并显示 5.2.2 作为版本。它在我的开发机器上运行良好。

4

9 回答 9

40

在和程序集的属性中设置为Copy Local并重新部署包。trueSystem.Web.HttpSystem.Web.Http.WebHost

如果这不能完全解决您的问题,请尝试重新安装 NuGet 包。这将有望纠正损坏的依赖关系。在包管理控制台中,运行以下命令:

Update-Package Microsoft.AspNet.WebApi -reinstall

确保也安装System.Web.Http.WebHost

于 2014-12-02T16:29:43.493 回答
12

对我来说,从“解决方案资源管理器”中,我检查了项目引用中“System.Web.Http”的版本,即 5.2.3.0,因此,在 web.config 中,我更改了:

<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" /> 

<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.3.0" />

然后构建。它对我有用!

于 2015-09-12T16:27:17.670 回答
3

在 web.cofig 中添加以下配置解决了我的问题。

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.5.0" />
  </dependentAssembly>
于 2018-05-09T08:09:57.147 回答
1

如果您在 GAC 中有一个具有不同版本的程序集,它将始终被加载,而不是来自 bin 文件夹的程序集。

于 2014-12-02T14:11:21.743 回答
1
  • 确保您在项目中引用了正确版本的 System.web.http(检查 web.config)。
  • 如果参考中不存在 System.web.http,请尝试使用 nugets 安装它。
  • 如果以上两点在您的本地都是正确的,那么尝试从包管理器控制台恢复您的 nugets
于 2019-12-12T07:16:40.687 回答
0

我遇到了同样的错误。这是由我用来部署应用程序的脚本引起的,该脚本用以前的版本替换了 Web.config。Web.config 指定了错误的 System.Web.Http 版本。删除该步骤解决了问题。

于 2016-05-11T13:42:58.653 回答
0

我通过以下步骤解决了这个问题:

  1. 将站点停止到远程 Web 服务器
  2. 清理站点文件夹
  3. 再次发布
  4. 启动网站

一键发布未替换正确版本的 dll 或远程站点正在使用该文件。

于 2019-03-28T15:38:19.410 回答
-1

愚蠢的建议,但在我的情况下,重新启动 Visual Studio 帮助了我。

于 2021-11-24T13:23:21.747 回答
-4

另一种不需要使用 Nuget 构建或更新/重新安装的方法是在 config.web 中执行以下操作:

对于您遇到问题的 dll,请执行以下操作:

&lt;bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="5.2.2.0"&gt;

我今天遇到了一个问题,这个小调整解决了它......

于 2015-10-16T21:54:07.190 回答