web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

CRM Authentication/Conectivity Issue

(0) ShareShare
ReportReport
Posted on by 30

I have a class library project already developed that create Products from F&O to Field Service through Integeration.

Microsoft has deprciated  the WS-Turst (Office 365 Authentication) and Recommended to use OAuth.

Integration has been break after Code update

Connection is fine at console app or when i consume hosted integration project but when it run through the D365 Finance and Operation it give below error.

""Unable to connect to CRM: Could not load type 'Microsoft.IdentityModel.Clients.ActiveDirectory.LogCallback' from assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.23.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.\r\nCould not load type 'Microsoft.IdentityModel.Clients.ActiveDirectory.LogCallback' from assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.23.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Unable to Login to Dynamics CRM\r\nUnable to Login to Dynamics CRMOrganizationWebProxyClient is null\r\nOrganizationWebProxyClient is nullOrganizationWebProxyClient is null\r\nOrganizationWebProxyClient is null""

CRM Connection Code is here 

private static string ConnectToMSCRM()
{

string connectionStatus = "";
try
{
//New Authentication OAuth
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

//New Authentication ClientSecret
var connectionString = "AuthType=ClientSecret;url=https://******.crm4.dynamics.com;ClientId=8b50f998-5a44-4307-8317-b6fb52bcf26c;ClientSecret=yty8Q~WdF3Xf8Nn0uTr4uCyJ0sUYD1K-KHd3Xapo";
CrmServiceClient crmConn = new CrmServiceClient(connectionString);
service = crmConn.OrganizationWebProxyClient ;

// Old obsolete code
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
//ClientCredentials credentials = new ClientCredentials();
//credentials.UserName.UserName = UserName;
//credentials.UserName.Password = Password;
//Uri serviceUri = new Uri(SoapOrgServiceUri);
//OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
//proxy.EnableProxyTypes();
//service = (IOrganizationService)proxy;
}

catch (Exception ex)
{
connectionStatus = "Error!"   "Error occurred while connecting to CRM "   ex.ToString();
}
return connectionStatus;

}

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Doublecheck that you have the right version of "Microsoft.IdentityModel.Clients.ActiveDirectory" references - the version should be 2.28.3.

    I have a little more in formation in my post - butenko.pro/.../

  • Sohail@@2156 Profile Picture
    30 on at

    Thanks Andrew,

    2022_2D00_06_2D00_28_5F00_13_2D00_26_2D00_06.png

    I have CRM online version 9.2 and using Xrm.Tooling.CoreAssembly version 9.1.0.13 which have dependency on Microsoft.IdentityModel.Active Directory version >=3.19.8

    The strange things is if I upgrage or downgrade the version of dll Microsoft.IdentityModel.Active Directory the execption is always 

    Exception:

    "Unable to connect to CRM: Could not load type 'Microsoft.IdentityModel.Clients.ActiveDirectory.LogCallback' from assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.23.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.\r\nCould not load type 'Microsoft.IdentityModel.Clients.ActiveDirectory.LogCallback' from assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.23.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Unable to Login to Dynamics CRM\r\nUnable to Login to Dynamics CRMOrganizationWebProxyClient is null\r\nOrganizationWebProxyClient is nullOrganizationWebProxyClient is null\r\nOrganizationWebProxyClient is null".

    Code is running is in console but when run through F&O plateform it give above exception.

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I created a supersimple console app exactly with your version of the Xrm Tooling and everything worked from the very first attempt.

    Here is what I have in packages:

    
      
      
      
      
      
      
    

    Here is the code I used:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Xrm.Tooling.Connector;
    
    namespace ConsoleApp7
    {
        class Program
        {
            static void Main(string[] args)
            {
                var service = new
                    CrmServiceClient("AuthType=ClientSecret; Url=https://instance.crm.dynamics.com; ClientId=Put Guid Here;ClientSecret=Put Your Secret Here");
    
                if (!service.IsReady)
                {
                    Console.WriteLine(service.LastCrmError);
                }
                else
                {
                    Console.WriteLine("Connected");
                }
    
                Console.ReadLine();
            }
        }
    }
    

    I used Framework 4.6.2.

  • Sohail@@2156 Profile Picture
    30 on at

    Yes, It is working in console as i mentioned already, but when same code run through F&O Interface/Platform it always show exception

     The same line of code running fine in console but confuse why when through F&O Platform it return all null (authority, token and OrganizationWebproxyclient)

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Ahh. Gotcha. Dunno how to help you here. One idea that I have in mind is to create some proxy (Azure Function for example) and call it from your F&O Code.

  • Volodymyr Vit Profile Picture
    5 on at

    Have you found a solution to this problem? I have the same error when I run it from F&O. In the console, everything works without errors.

  • Sohail@@2156 Profile Picture
    30 on at

    Yes, Volodymyr Vit 

    1st  you need to get Token from Azure Active Directory by passing the tenant id in given blow code and then pass it to OrganizationWebProxyClient.

    Here is sample code that i used and it solve the issue and working in F&O side

    static IOrganizationService service = null;
    
    private static string ConnectToMSCRM(string clientId, string clientSecret, string url)
    {
    string connectionStatus = "";
    try
    {
    #region New Online CRM Authentication Auth 2.0
    // Dynamics CRM Online Instance Base URL
    string crmBaseUrl = url;
    // client id and client secret of the application
    ClientCredential clientCrendential = new ClientCredential(clientId, clientSecret);
    // Authenticate the registered application with Azure Active Directory.
    Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext("https://login.microsoftonline.com/53b0f650-ed58-4cf1-b3af-776ee*******");
    
    AuthenticationResult authResult = authContext.AcquireTokenAsync(crmBaseUrl, clientCrendential).Result;
    var accessToken = authResult.AccessToken;
    
    Uri serviceUrl = new Uri(crmBaseUrl   @"/XRMServices/2011/Organization.svc/web?SdkClientVersion=9.2");
    using (OrganizationWebProxyClient orgWebProxyClient = new OrganizationWebProxyClient(serviceUrl, false))
    {
    orgWebProxyClient.HeaderToken = accessToken;
    service = orgWebProxyClient != null ? (IOrganizationService)orgWebProxyClient : null;
    
    }
    
    #endregion
    }
    catch (Exception ex)
    {
    connectionStatus = "Error!"   "Error occurred while connecting to CRM "   ex.ToString();
    }
    return connectionStatus;
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 72 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 29 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans