Could not load file or assembly “System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”

后端 未结 15 1452
滥情空心
滥情空心 2020-11-28 18:31

I\'ve copied my project to a clean Windows 10 machine with only Visual Studio 2015 Community and SQL Server 2016 Express installed. There are no other framework versions ins

相关标签:
15条回答
  • 2020-11-28 18:52

    The above bind-redirect did not work for me so I commented out the reference to System.Net.Http in web.config. Everything seems to work OK without it.

      <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>
    
    0 讨论(0)
  • 2020-11-28 18:52

    This will work in .NET 4.7.2 with Visual Studio 2017 (15.9.4):

    • Remove web/app.config binding redirects
    • Remove NuGet package for System.Net.Http
    • Open "Add New Reference" and directly link to the new 4.2.0.0 build that ships with .NET 4.7.2

    0 讨论(0)
  • 2020-11-28 18:54

    For me, I had set my project to run on the latest version of .Net Framework (a change from .Net Framework 4.6.1 to 4.7.2).

    Everything worked, no errors and published without issue, and it was only by chance that I came across the System.Net.Http error message, shown in a small, hard-to-notice, but quite important API request over the website I'm working on.

    I rolled back to 4.6.1 and everything is fine again.

    0 讨论(0)
  • 2020-11-28 18:58

    Follow the following steps,

    1. Update visual studio to latest version (it matters)
    2. Remove all binding redirects from web.config
    3. Add this to the .csproj file:

      <PropertyGroup>
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
        <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
      </PropertyGroup>
      
    4. Build the project
    5. In the bin folder there should be a (WebAppName).dll.config file
    6. It should have redirects in it, copy these to the web.config
    7. Remove the above snipped from the .csproj file

    It should work

    0 讨论(0)
  • 2020-11-28 18:58

    Changing the binding information in my web.config (or app.config) - while a "hack" in my view, allows you to move forward with your project after a NuGet package update whacks your application and gives you the System.Net.Http error.

    Set oldVersion="0.0.0.0-4.1.1.0" and newVersion="4.0.0.0" as follows

    <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>
    
    0 讨论(0)
  • 2020-11-28 18:58

    The only way that cleanly solved this issue for me (.NET 4.6.1) was to not only add a Nuget reference to System.Net.Http V4.3.4 for the project that actually used System.Net.Http, but also to the startup project (a test project in my case).

    (Which is strange, because the correct System.Net.Http.dll existed in the bin directory of the test project and the .config assemblyBingings looked OK, too.)

    0 讨论(0)
提交回复
热议问题