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;
}