In this post, I have tried to explain both the root cause & solution for the above error.
You normally get this issue when you take the reference of a certain third-party library in your application.
For example, you took the reference of RestSharp (A third-party library) from NuGet. That RestSharp internally may have used the reference of
220.127.116.11 version. And your project is also using the reference to
18.104.22.168 (From GAC). Now when you run the application & try to call any method which is using RestSharp, at the same time Runtime (CLR) tries to locate the
System.Net.Http assembly with version
22.214.171.124 & when it fails to locate the desired version, it throws
System.IO.FileNotFoundException exception with below error message.
Could not load file or assembly 'System.Net.Http, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of > its dependencies. The system cannot find the file specified.
Here you can see How the Runtime Locates Assemblies?
Just add the below configuration in the
app.config of your startup project.
<dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-188.8.131.52" newVersion="184.108.40.206" /> </dependentAssembly>
This configuration instructs the runtime to resolve
System.Net.Http assembly with
220.127.116.11 version only, whenever it looks for this assembly for any version between
Here is the complete schema:
<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-18.104.22.168" newVersion="22.214.171.124" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
Hopefully, this should fix the issue. If not, just let me know your comments in below comment box.