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

后端 未结 15 1451
滥情空心
滥情空心 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 19:03

    I have same issue and only way how i am able to fix it is add bindingRedirect to app.confing how wrote @tripletdad99.

    But if you have solution with more project is really suck update every project by hand (and also sometimes after update some nuget package you need to do it again). And it is reason why i wrote simple powershell script which if all app.configs.

     param(
        [string]$SourceDirectory,
        [string]$Package,
        [string]$OldVersion,
        [string]$NewVersion
    )
    
    Write-Host "Start fixing app.config in $sourceDirectory"
    Write-Host "$Package set oldVersion to $OldVersion and newVersion $NewVersion"
    Write-Host "Search app.config files.."
    [array]$files = get-childitem $sourceDirectory -Include app.config App.config -Recurse | select -expand FullName
    foreach ($file in $files)
    {
        Write-Host $file
        $xml = [xml](Get-Content $file)
        $daNodes = $xml.configuration.runtime.assemblyBinding.dependentAssembly
        foreach($node in $daNodes)
        {
            if($node.assemblyIdentity.name -eq $package)
            {
                $updateNode = $node.bindingRedirect
                $updateNode.oldVersion = $OldVersion
                $updateNode.newVersion =$NewVersion
                Write-Host "Fix"
            }
        }
        $xml.Save($file)
    }
    
    Write-Host "Done"
    

    Example how to use:

    ./scripts/FixAppConfig.ps1 -SourceDirectory "C:\project-folder" -Package "System.Net.Http" -OldVersion "0.0.0.0-4.3.2.0" -NewVersion "4.0.0.0"
    

    Probably it is not perfect and also it will be better if somebody link it to pre-build task.

    0 讨论(0)
  • In one of my projects there was a nuget packages with higher version of System.Net.Http. and in my startup project there reference to System.Net.Http v 4.0.0 , i just installed System.Net.Http nuget package in my startup project and the problem solved

    0 讨论(0)
  • 2020-11-28 19:04

    Was updating an old website using nuget (including .Net update and MVC update).

    I deleted the System.Net.HTTP reference in VS2017 (it was to version 2.0.0.0) and re-added the reference, which then showed 4.2.0.0.

    I then updated a ton of 'packages' using nuget and got the error message, then noticed something had reset the reference to 2.0.0.0, so I removed and re-added again and it works fine... bizarre.

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