It seems that your project has used a newer version dll about System.Net.Http
and if some dependencies use the old version 4.0.0.0 System.Net.Http.dll
, it will miss the old one.
Besides, please the following steps:
1) make sure that your xxx.csproj
file has this node, if not, you should modify like this:
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
Also, try to set Copy Local of System.Net.Http.dll
to true
.
Modify such node like this in xxx.csproj
file:
<Reference Include="System.Net.Http">
<Private>True</Private>
</Reference>
2) open CMD as Administrator and then type:
cd C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools
gacutil /i xxxxx\System.Net.Http.dll(path where the System.Net.Http.dll exists)
// like the path C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Net.Http.dll
3) Maybe you could try this in app.config
file:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0"
newVersion="4.2.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
There is a similar issue about it.
4) then delete bin
and obj
folder and then use Build Tool for VS2017 to build the project again.
=====================================================
Update 1
Thanks for sharing your solution. Actually, Not sure that whether system cannot find the System.Net.Http
when you move your project into Build agent.
Actually, you can use hintpath to force the path to reference System.Net.Http
in your project and make sure that they are the same. Also, this solution will make sure the dll will copied into output folder. And it will make VS or msbuild find and identify the DLL.
And you have changed the location of the DLLL to the same so that the issue is fixed.
You can try to use this in your xxx.csproj
file:
It will also copy such dll into output folder.
<Reference Include="System.Net.Http">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Net.Http.dll</HintPath>
</Reference>
or
<Reference Include="System.Net.Http">
<HintPath>C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Net.Http.dll</HintPath>
</Reference>
hintpath
of theSystem.Net.Http.dll
to a specific path. And use that to make sure that they use the same path or similar path. Also, thanks for sharing your solution and glad to know the issue went away. I have added your solution into my answer and some details. You can check it. See myupdate 1
:) And if it helps, you could consideraccept it
. – Mr Qian