我已将项目复制到仅安装了 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/