While trying to connect
to Dynamics CRM Online via an MVC application, I was having below error
ERROR REQUESTING Token FROM THE Authentication contextException has been thrown by the target of an invocation. => Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.Unable to connect to CRM: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Unable to
Login to Dynamics CRMOrganizationWebProxyClient is null
OrganizationWebProxyClient
is null
Root Cause:
You normally get this issue when you take the reference of
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 System.Net.Http
4.2.0.0
version. And your
project is also using the reference to System.Net.Http
4.0.0.0
(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 4.2.0.0
& when it
fails to locate the desired version, it throws System.IO.FileNotFoundException
exception with
below error message.
Solution:
Just add the below configuration in the web.config
or app.config
of your startup project.
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
Hopefully, this should fix the issue.
Here are some other links for Troubleshooting and learning: