c# - 无法加载文件或程序集 "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

标签 c# azure visual-studio-2015

我已将项目复制到仅安装了 Visual Studio 2015 Community 和 SQL Server 2016 Express 的干净 Windows 10 计算机。除了随 Windows 10 和 VS2015 或 SQL Server 安装的框架版本外,没有安装其他框架版本。

当我尝试启动 WebApi 项目时,我收到消息:

Could not load file or assembly "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" or one of its dependencies. The system cannot find the file specified.

该项目的包包括:

<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" />

使用 .NET Framework 4.6.1 构建项目后,在 bin 文件夹中找不到 System.Net.Http 文件。

文件的路径指向:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.1\System.Net.Http.dll

System.Net.Http.Formatting的文件路径指向:

C:\Development\MyApp\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll

整个项目应该以 4.5.1 为目标还是有其他方法来引用正确的程序集?

最佳答案

更改我的 web.config(或 app.config)中的绑定(bind)信息 - 虽然在我看来是“黑客”,但允许您在 NuGet 包更新破坏您的应用程序并为您提供 System.Net.Http 错误。

设置oldVersion="0.0.0.0-4.1.1.0"newVersion="4.0.0.0"如下

<dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.0.0.0" />
</dependentAssembly>

关于c# - 无法加载文件或程序集 "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38408167/

相关文章:

c# - DataGridView 绑定(bind)

c# - 为什么AsynchResult 存储在.NET framework 中的System.Runtime.Remoting.Messaging 中?

c# - 使用C#执行Powershell命令(azureVM)

windows - 当我的角色 Azure VM 被回收时,其他 Azure 角色是否可以读取我的角色留下的未删除磁盘数据?

asp.net-mvc - Visual Studio 2015新建MVC项目-Microsoft.Aspnet中不存在mvc

visual-studio-2015 - 分析数据库模式。 X 操作完成后,您的数据库项目将准备就绪 - VS 2015 Pro 性能不足

c# - .NET 字符串格式 - 小数点左边的 # 是什么意思?

c# - 将数据导入临时数据库并在使用 MVC 完成后重命名

sql-server - 如何向外部用户授予对我的 Azure 数据库的访问权限?

c++ - Visual Studio 2015 Update 3 是否破坏了构造函数属性?