I've created a new project in VS2017 targeting the .NET Framework 4.6.1, and when I add a NuGet package reference to System.Net.Http, I get the following warning for it and all of its depencencies:
The referenced component 'System.Net.Http' could not be found.
The project (and its solution) compile but when I run, I get an exception because the assembly can't be found when trying to instantiate an instance of HttpClient
.
I have confirmed that the HintPath
is pointing to the correct location in the packages folder and the DLL is there with a size of 193 KB. I've removed the reference, and tried to add the reference to the DLL directly without success.
I've also tried to add a reference to through Framework > Assemblies, but no matter what I do, the reference has a warning icon, and the properties for the reference look like this:
I've tried the following:
Update-Package -reinstall
with the appropriate argumentsIt seems that no matter what I try, I can't get the reference to work. What other things should I be trying?
TLDR - Service Fabric services don't work well with project references to .NET Standard packages; instead, use the full .NET Framework for class libraries.
After several more hours of trial and error, I was able to determine that the issue was not with the System.Net.Http
package itself, but was the result of a reference to another project within the solution.
If I referenced the project targeting netstandard1_6, the System.Net.Http
references (including the dependent packages) would not load or resolve. Once I removed the project reference, they loaded fine! Ultimately, I changed my referenced project to a "regular" .NET Framework project, added a reference to that version, and all my references were fine.
There are a few things that we suspect, but aren't sure which was the ultimate cause:
Any additional explanation would be appreciated!
Today I ran into this issue. In my case the cause was that I have Dependency Behavior in the NuGet options set to 'Lowest', which downloads the lowest compatible versions of dependent packages. Unfortunately this sometimes means it downloads a package version that is not compatible with your project's runtime version. In my case, package System.Net.Http.Formatting.Extensions caused System.Net.Http version 2.20... to be installed, which was not recognized by my .NET 4.7.1 project.
On the Updates tab in the Nuget Package manager for the solution, it will show updates for these packages. Install them and your problem should be solved. Alternatively, set the Dependency Behavior to Highest when installing NuGet packages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With