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 :
Microsoft Dynamics CRM (Archived)

Problem in using services related to Microsoft.Xrm.Client.dll in D365

(0) ShareShare
ReportReport
Posted on by 115

Hi,

I am unable to use the services that we retrieve from the "Microsoft.Xrm.Client.dll" in D365.

I have used Microsoft.Xrm.Tooling.Connector.dll instead of the above mentioned dll as it was not available in D365 SDK. But now i am facing the  Error : while retrieving records  "An exception of type 'System.NullReferenceException' occurred in Microsoft.Xrm.Tooling.Connector.dll but was not handled in user code"

Here is my piece of code. Any suggestions would be really helpful.

string connStr = ConfigurationManager.ConnectionStrings["Xrm"].ConnectionString;

using (CrmServiceClient service = new CrmServiceClient(connStr))
{
QueryExpression query = new QueryExpression();
query.EntityName = "account";
query.ColumnSet = new ColumnSet(new string[] { "name", "telephone1", "fax"});
query.Criteria.AddCondition(new ConditionExpression("name", ConditionOperator.NotNull));

EntityCollection accountRecord = service.RetrieveMultiple(query);

}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Bhaargavi,

    You need to check if the service is ready.

    Check the below links-

    msdn.microsoft.com/.../dn688175.aspx

    community.dynamics.com/.../simple-dynamics-crm-console-application

    Here is a youtube video which you can refer-

    www.youtube.com/watch

    You may also want to check if you are using the connection string correctly-

    msdn.microsoft.com/.../dn688177.aspx

    Hope this helps.

  • Verified answer
    Bhaargavi Bodapati Profile Picture
    115 on at

    Ravi, many thanks :)

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Check your connection string:

    You can use one of the following methods as well (added next to lines to verify connection is working):

    CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);

    _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

    Guid userid = ((WhoAmIResponse)_orgService.Execute(new WhoAmIRequest())).UserId;

    You can also use alternate method if that's not working:

    string userName = ConfigurationManager.AppSettings["UserName"].ToString();

    string password = ConfigurationManager.AppSettings["Password"].ToString();

    string internalUrl = ConfigurationManager.AppSettings["InternalUrl"].ToString();

    string orgName = ConfigurationManager.AppSettings["OrgName"].ToString();

    NetworkCredential creds = new NetworkCredential(userName, ConvertToSecureString(password));

    Microsoft.Xrm.Tooling.Connector.AuthenticationType authType = Microsoft.Xrm.Tooling.Connector.AuthenticationType.IFD;

    CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(creds, authType, internalUrl, "443", orgName, true, true, null);

    // Cast the proxy client to the IOrganizationService interface.

    _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

    Guid userid = ((WhoAmIResponse)_orgService.Execute(new WhoAmIRequest())).UserId;

    // ConvertToSecureString method from above.

           private System.Security.SecureString ConvertToSecureString(string password)

           {

               if (password == null)

                   throw new ArgumentNullException("missing pwd");

               var securePassword = new System.Security.SecureString();

               foreach (char c in password)

                   securePassword.AppendChar(c);

               securePassword.MakeReadOnly();

               return securePassword;

           }

    Hope this helps.

  • Community Member Profile Picture
    on at

    Hi Ravi, I am getting below error - an unhandled exception of type system.nullreferenceexception occurred in Microsoft.XRM.Tooling.Connector.dll

    My code is -

    string crmConnectionString = ConfigurationManager.AppSettings["CRMConnectionString"];

               CrmServiceClient service = new CrmServiceClient(crmConnectionString);

               WhoAmIResponse whoAmIResponse = (WhoAmIResponse)service.Execute(new WhoAmIRequest());

               QueryExpression query_Contacts = new QueryExpression("contact");

               query_Contacts.ColumnSet = new ColumnSet("Accountname", "Fullname");

               EntityCollection coll_Contacts = service.RetrieveMultiple(query_Contacts);

    Can you please help

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans