Using VS2017, I created ClassLibrary (.NET Framework 4.6.2) in an empty solution. Then I installed System.Net.Http 4.3.2 and used the HttpClient class in the constructor of Class1 .
Then I created ConsoleApp (.NET Framework 4.6.2) referencing ClassLibrary and an instance of Class1 in the Main method.
Now running ConsoleApp raises an exception at runtime:
Unhandled exception: System.IO.FileNotFoundException: Failed to load file or assembly 'System.Net.Http, Version = 4.1.1.1, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the specified file. in ClassLibrary1.Class1..ctor () in ConsoleApp1.Program.Main (String [] args) in [...]
In the detailed build log, I see this message:
2> There was a conflict between "System.Net.Http, Version = 4.0.0.0", Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a "and" System.Net.Http, Version = 4.1.1.1, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a ".
2> "System.Net.Http, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" was selected because it was primary and "System.Net.Http, Version = 4.1.1.1, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a "was not.
Suppose I cannot remove the link to System.Net.Http from ConsoleApp , because I have this situation in the real structure of the project.
- Playing with the
Specific Version System.Net.Http link parameter did not help. - Specifying
<bindingRedirect oldVersion="0.0.0.0-4.1.1.1" newVersion="4.1.1.1" /> did not help
I searched for it, and this is a popular problem, but I did not find a clear explanation of what is actually happening, and how to fix such cases in general.
Failed to load file or assembly System.Net.Http version 4.1.1.0
Failed to load file or assembly "System.Net.Http" or one of its dependencies
About conflicts:
What does .NET mean when choosing "primary" when choosing between a conflict dll link?
Conflicts were found between different versions of the same dependent assembly that could not be fixed.