4

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 Answers3

1

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.

Dennis Rieke
  • 201
  • 4
  • 18
1

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).

vvv
  • 31
  • 2
0

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}"
  />
  • Thank you so much Arun for the response, Actually we have referred the same link that you have provided and also validated the "https://contosotest.crm.dynamics.com". Do you have any more idea about this? – Inkey Solutions Oct 09 '20 at 12:57
  • @InkeySolutions hmm interesting, something should be silly to tweak to make it work. Let me check on my end too – Arun Vinoth-Precog Tech - MVP Oct 11 '20 at 23:09