3
votes

We are trying to connect Dynamics 365 Unified Interface instance via C# code (WebAPI hosted at Azure) using Microsoft.CrmSdk.XrmTooling.CoreAssembly with the parameters ClientId and ClientSecret. but we are getting below error.

"Unable to connect to CRM: Method not found: 'System.String Microsoft.Xrm.Sdk.Organization.OrganizationDetail.get_EnvironmentId()'. Method not found: 'System.String Microsoft.Xrm.Sdk.Organization.OrganizationDetail.get_EnvironmentId()'.Unable to Login to Dynamics CRM Unable to Login to Dynamics CRMOrganizationWebProxyClient is null OrganizationWebProxyClient is null"

Please note, we have used latest NuGet version of "Microsoft.CrmSdk.XrmTooling.CoreAssembly" with the Framework 4.6.2.

Below is the code that we have written

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

    IOrganizationService organizationService = null;

    string organizationURI = "https://OrgName.api.crm.dynamics.com/XRMServices/2011/Organization.svc";
    string clientId = "Clientid";
    string clientSecret = "ClientSecret";

    var connection = new CrmServiceClient($@"AuthType=ClientSecret;url={organizationURI};ClientId={clientId};ClientSecret={clientSecret}");

    if (connection.IsReady)
    {
      organizationService = connection.OrganizationWebProxyClient != null ? connection.OrganizationWebProxyClient : (IOrganizationService)connection.OrganizationServiceProxy;
    }
3
I get the same error with AuthType OAuth and Office365. Is there any solution?Dennis Rieke
Looks like you are connecting to soap endpoint. Were you meant to connect to REST (web api) endpoint possible?siggi_pop

3 Answers

1
votes

I had the same problem and after I deleted every .dll file and reinstalled them, it worked. So, I guess you have a problem with a .dll-version.

1
votes

I needed to use Microsoft.CrmSdk.XrmTooling.CoreAssembly 9.1.0.25 for compatibility with Azure Functions v1's old Newtonsoft.Json version, and was getting this error until I installed a newer version of Microsoft.CrmSdk.CoreAssembly (the newest version at the time worked, 9.0.2.27 and 9.0.2.33 in two different apps).

0
votes

Hope you have done the pre-requisite steps like Application User creation in CRM & Azure AD App registration and the latest version is 9.1.0.13 or higher in order to connect using ClientSecret. Reference

Also there is a problem in your organizationURI. This endpoint /XRMServices/2011/Organization.svc is deprecated and will be removed anytime.

Instead use https://contosotest.crm.dynamics.com for connecting. Read more

<add name="MyCDSServer" 
  connectionString="
  AuthType=ClientSecret;
  url=https://contosotest.crm.dynamics.com;
  ClientId={AppId};
  ClientSecret={ClientSecret}"
  />