Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

Posted on by Microsoft Employee

Greetings:

I'm trying the examples in the SDK, and now I'm at the Simplified Connecting String Example listed here [https://msdn.microsoft.com/en-us/library/jj602970(v=crm.7).aspx]

This is my code in the app.config:

 

<add name="Server=CRM Online, organization=contoso, user=someone"
         connectionString="Url=https://pspas.crm.dynamics.com;
Username=nxxxx.mxxxz@pspas.onmicrosoft.com;
Password=xxxx;
authtype=Office365"/>


However, I'm receiving the following error:

I'm using VS 2015 and I'm trying to connect to CRM Online 2016.

What I'm missing in my connection string?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

    I was receiving the same error when trying to connect the on premise CRM for developing a console application. Using the unique org name still didn't fix the problem. I have changed my connection string as following and it works fine now.

    In program.cs file

    string connectionstring = ConfigurationManager.ConnectionStrings["DynamicsCRM365"].ConnectionString;
    Microsoft.Xrm.Tooling.Connector.CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionstring);
    IOrganizationService service = conn.OrganizationServiceProxy;

    In App.Config (Or put it in Web.Config)

    <connectionStrings>
    <add name="DynamicsCRM365" connectionString="Url=https://yourcrmurl/orgname; Domain=domainname;UserName=username;Password=password;authtype=AD" />
    </connectionStrings>

    Hope, the above example will help you. 

     

    Thanks

    Syed Jafri

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

    Thank you Daniel! I've been struggling so much on how different not reliable is the MSDN references. I hope they can update documentation as rapidly they are pushing updates to the SDK.

  • Suggested answer
    Rahul G J Profile Picture
    Rahul G J 605 on at
    RE: SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

    Hi Nell,

    You can try directly using the URL of the CRM as nithya said. Hope it works

    Regards,

    Rahul

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

    Hi,

    Can try using the following code? 

    IOrganizationService services = CRMConnectionDefault();
    
    public static IOrganizationService CRMConnectionDefault()
    
            {
                ClientCredentials credentials = new ClientCredentials();
                credentials.Windows.ClientCredential = new System.Net.NetworkCredential("userName", "password", "domain");
                Uri organizationUri = new Uri("http://url/domain/XRMServices/2011/Organization.svc");
                OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null);
                serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                serviceProxy.Timeout = new TimeSpan(0, 6, 0);
                return (IOrganizationService)serviceProxy;
            }

    Hope it helps,

    Ezgi Haglund
    Please verify if it solves your problem

  • Verified answer
    Daniel Wikell Profile Picture
    Daniel Wikell 2,360 on at
    RE: SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

    Hi!

    Are you using the CRM 2016 SDK? There's apparently a bug in it making it require the unique organisationname to be used in the url instead of your organisation display name.

    Aileen recently wrote a blog post for this and it solved my issues with accessing the organizationservice with the 2016 SDK:

    community.dynamics.com/.../error-quot-unable-to-login-to-dynamics-crmorganizationwebproxyclient-is-nullorganizationwebproxyclient-is-nullorganizationserviceproxy-is-nullorganizationserviceproxy-is-null-quot-during-connecting-to-crm-online-using-xrm-too

  • Suggested answer
    ansrikanth Profile Picture
    ansrikanth 3,115 on at
    RE: SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

    you shouldn't be using the Discovery service to connect to CRM Organization. Have you tried the solution provided by @Nadeeja Bomiriya above?

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

    Hi,

    You could use the following connection string.

    Url=https://devcrm.vzdev.ch/devcrm;Domain=vzdev;UserName=user@vzdev.ch;Password=pass;AuthType=IFD

    Also refer the link below.

    https://msdn.microsoft.com/en-in/library/mt608573.aspx

    See: https://community.dynamics.com/crm/f/117/t/199661

           https://community.dynamics.com/crm/f/117/t/197001

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

    Hi Nithya;

    My connection strings looks like this at this moment:  

    <add name="Server=CRM Online"         connectionString="Url=disco.crm.dynamics.com/.../v8.1;Username=xxxx.xxxx@pspas.onmicrosoft.com;Password=xxxx!;Domain:pspas;"/>

    And now I'm receiving this error;

    The application terminated with an error.

    Organization name cannot be null or empty.

    Parameter name: Organization Name

    {System.ArgumentNullException: Organization cannot be null or empty.

    Parameter name: Organization Name

      at Microsoft.Xrm.Tooling.Connector.CrmServiceClient.ConnectToCrmWebService(String crmConnectionString)

      at Microsoft.Xrm.Tooling.Connector.CrmServiceClient..ctor(String crmConnectionString)

      at Microsoft.Crm.Sdk.Samples.SimplifiedConnection.Run(String connectionString, Boolean promptforDelete) in C:\Development\CRM\SDK\SampleCode\CS\QuickStart\SimplifiedConnection.cs:line 70

      at Microsoft.Crm.Sdk.Samples.SimplifiedConnection.Main(String[] args) in C:\Development\CRM\SDK\SampleCode\CS\QuickStart\SimplifiedConnection.cs:line 285}

  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    Nadeeja Bomiriya 6,804 on at
    RE: SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

    Hi NellMartinez,

    I just tested this and had issues with the latest version of Microsoft.IdentityModel.Clients.ActiveDirectory assembly.  I downgraded it to 2.28.0 and it works.

    Here's the code.

    var connectionString = "Url=https://orgname.crm.dynamics.com; Username=user@orgname.onmicrosoft.com; Password=password; authtype=Office365";
    
    // Connect to the CRM web service using a connection string.
    CrmServiceClient conn = new CrmServiceClient(connectionString);
    
    // Cast the proxy client to the IOrganizationService interface.
    var _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
    

    Please see below for the NuGet packages and versions I have installed in my console app.

    NuGet-Packages.PNG

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: SDK Simplified connection string in app.config: "Object reference not set to an instance of an object."

    Hi,

    Please try the steps provided in the blog below to establish the connection to CRM. It provides a simple example too.

    arunpotti.wordpress.com/.../connect-to-crm-online-or-on-premise-using-c

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans