You may encounter this problem when referencing different assemblies containing proxy classes, i.e. one assembly wrapping the server SDK (Microsoft.Xrm.Sdk) and another assembly terminating the client SDK (Microsoft.Xrm.Sdk.Client). In such a scenario, it seems necessary to tell OrganizationServiceProxy that the assembly should be used to resolve proxy classes.
This should help:
var credentials = new ClientCredentials(); credentials.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain); var proxy = new OrganizationServiceProxy(new Uri(discoveryUrl), null, credentials, null); proxy.EnableProxyTypes(typeof(CrmServiceContext).Assembly); var context = CrmServiceContext(proxy);
It is important to call EnableProxyTypes, passing the correct assembly. I saw another solution using CrmConnection , but CrmConnection is only available in the client SDK, which means that you cannot create an instance of the "server-OrganizationServiceProxy" of this path. EnableProxyTypes (assembly assembly) works for both sides.
Hope this helps.
Regards, MH
Martin jesch
source share