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

当我尝试启动WebApi项目时,我得到了这样的消息:

无法加载文件或程序集"System.Net。Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。系统无法找到指定的文件。

项目包包括:

<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程序集\Microsoft\ framework.net框架\v4.6.1\System.Net.Http.dll

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

C: \开发\ MyApp \ \ Microsoft.AspNet.WebApi.Client.5.2.3 \ lib \ net45 \ System.Net.Http.Formatting.dll包

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


当前回答

正在使用nuget更新旧网站(包括. net更新和MVC更新)。

我在VS2017中删除了System.Net.HTTP引用(它是版本2.0.0.0),并重新添加了引用,然后显示为4.2.0.0。

然后我用nuget更新了大量的“包”,并得到了错误消息,然后注意到一些东西将引用重置为2.0.0.0,所以我删除并重新添加,它工作正常…怪异。

其他回答

上面的绑定-重定向对我不起作用,所以我在web.config中注释掉了对System.Net.Http的引用。没有它,一切似乎都可以正常工作。

  <system.web>
    <compilation debug="true" targetFramework="4.7.2">
      <assemblies>
        <!--<add assembly="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />-->
        <add assembly="System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>
    <customErrors mode="Off" />
    <httpRuntime targetFramework="4.7.2" />
  </system.web>

对我来说,唯一干净利落地解决这个问题的方法。NET 4.6.1)不仅为实际使用System.Net的项目添加了对System.Net.Http V4.3.4的Nuget引用。Http,但也启动项目(在我的情况下是一个测试项目)。

(这很奇怪,因为正确的System.Net.Http.dll存在于测试项目的bin目录中,.config assemblyBingings看起来也不错。)

请遵循以下步骤:

Update Visual Studio to to latest version (it matters) Remove all binding redirects from web.config Add this to the .csproj file: <PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup> Build the project In the bin folder there should be a (WebAppName).dll.config file It should have redirects in it, copy these to the web.config Remove the above snipped from the .csproj file

它应该会起作用。

对我来说,我已经将我的项目设置为在最新版本的。net Framework上运行(从。net Framework 4.6.1到4.7.2的更改)。

一切都正常工作,没有错误,发布也没有问题,只是由于偶然的机会,我遇到了System.Net.Http错误消息,它显示在我正在工作的网站上的一个很小的,很难注意到的,但非常重要的API请求中。

我回滚到4.6.1,一切恢复正常。

我在把项目从。net Framework 4.6升级到。net Framework 4.8后遇到了这个问题。在配置文件中,我仍然有旧版本的行

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>

并且服务器没有安装。net Framework 4.8。

在纠正上面的代码行之后,在服务器上安装。net Framework 4.8并重新启动它,现在它可以工作了。