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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

system.argumentnullexception value cannot be null. parameter name device credentials

(0) ShareShare
ReportReport
Posted on by

Hello, 

i have a code to get an organization with online and on premise parametres 

with onpremise , the program work fine but when i choose online deployment i get the error " system.argumentnullexception value cannot be null. parameter name device credentials" 

this is my code 

 public static List<string> GetOrganizations(ConnectionParams connectionParams)
        {

            ClientCredentials userCredentials = new ClientCredentials();
            userCredentials.Windows.ClientCredential = new System.Net.NetworkCredential();

            List<string> orgNames = new List<string>();
            switch (connectionParams.Deployment)
            {
                case DeploymentTypes.OnPremise:
                    if (connectionParams.UseDefaultCredentials)
                    {
                        userCredentials.Windows.ClientCredential = new System.Net.NetworkCredential();
                    }
                    else
                    {
                        userCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(connectionParams.UserName, connectionParams.Password, connectionParams.Domain);
                      
                    }

                    break;
                case DeploymentTypes.Online:                                        
                    userCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(connectionParams.UserName, connectionParams.Password);
                    break;
                default:
                    break;
            }



            DiscoveryServiceProxy discoveryProxy = new DiscoveryServiceProxy(new Uri(connectionParams.DiscoveryUrl), null, userCredentials, null);
            discoveryProxy.Authenticate();

            RetrieveOrganizationsRequest retrieveOrganizationsRequest = new RetrieveOrganizationsRequest();
            RetrieveOrganizationsResponse retrieveOrganizationsResponse = discoveryProxy.Execute(retrieveOrganizationsRequest) as RetrieveOrganizationsResponse;
            if (retrieveOrganizationsResponse.Details.Count != 0)
            {
                foreach (OrganizationDetail orgInfo in retrieveOrganizationsResponse.Details)
                    orgNames.Add(orgInfo.UrlName);
            }
return orgNames; 
}

Thanks for your help

*This post is locked for comments

I have the same question (0)
  • yosra.walid Profile Picture
    on at
    RE: system.argumentnullexception value cannot be null. parameter name device credentials

    I can't work with the simple connexion , iwork with a big project with windows forms application for client and i must respect the procedure of the methode ,

    the methode is the getOrganization

    and for the DeviceCredentials  i connect with office 365 authentification and always i have the error system.invalidoperationexception the username is not provided. specify username in clientcredentials even i specifier the username

  • yosra.walid Profile Picture
    on at
    RE: system.argumentnullexception value cannot be null. parameter name device credentials

    Even i add this code to my function but still show me the error

    this is my code

    public static List<string> GetOrganizations(ConnectionParams connectionParams)

           {

               ClientCredentials userCredentials = new ClientCredentials();

               userCredentials.Windows.ClientCredential = new System.Net.NetworkCredential();

               ClientCredentials deviceCreds = new ClientCredentials();

               deviceCreds.Windows.ClientCredential = new System.Net.NetworkCredential();

               deviceCreds = DeviceIdManager.LoadOrRegisterDevice();

               List<string> orgNames = new List<string>();

               switch (connectionParams.Deployment)

               {

                   case DeploymentTypes.OnPremise:

                       if (connectionParams.UseDefaultCredentials)

                       {

                           userCredentials.Windows.ClientCredential = new System.Net.NetworkCredential();

                       }

                       else

                       {

                           userCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(connectionParams.UserName, connectionParams.Password, connectionParams.Domain);

                       }

                       break;

                   case DeploymentTypes.Online:

                       {

                           userCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(connectionParams.UserName, connectionParams.Password);

                           deviceCreds.Windows.ClientCredential = new System.Net.NetworkCredential(connectionParams.UserName, connectionParams.Password);

                       }

                       break;

                   default:

                       break;

               }

               DiscoveryServiceProxy discoveryProxy = new DiscoveryServiceProxy(new Uri(connectionParams.DiscoveryUrl), null, userCredentials, deviceCreds);

               discoveryProxy.Authenticate();

               RetrieveOrganizationsRequest retrieveOrganizationsRequest = new RetrieveOrganizationsRequest();

               RetrieveOrganizationsResponse retrieveOrganizationsResponse = discoveryProxy.Execute(retrieveOrganizationsRequest) as RetrieveOrganizationsResponse;

               if (retrieveOrganizationsResponse.Details.Count != 0)

               {

                   foreach (OrganizationDetail orgInfo in retrieveOrganizationsResponse.Details)

                       orgNames.Add(orgInfo.UrlName);

               }

  • yosra.walid Profile Picture
    on at
    RE: system.argumentnullexception value cannot be null. parameter name device credentials

    Thank you for your answer,

    after i work with deviceidmanager  class and i use ClientCredentials deviceCreds = DeviceIdManager.LoadOrRegisterDevice(); in my code

    i get this error " the username is not provided specify a username in the client credentials"

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: system.argumentnullexception value cannot be null. parameter name device credentials

    You can use like below

    // Create and configure the Discovery Service web service
    ClientCredentials deviceCreds = DeviceIdManager.LoadOrRegisterDevice();

    //Create discovery service proxy
    DiscoveryServiceProxy _discovery =
    new DiscoveryServiceProxy(new Uri("https://disco.crm5.dynamics.com/XRMServices/2011/Discovery.svc"), null, _Credentials, deviceCreds);

    You need to include deviceidmanager class in your solution, you can get this class from SDK under SDK\SampleCode\CS\HelperCode localtion

  • yosra.walid Profile Picture
    on at
    RE: system.argumentnullexception value cannot be null. parameter name device credentials

    This function is to get Organization so the in this function idon't have the uri of organization so how i can work with device credentials and i work with windows form application

  • yosra.walid Profile Picture
    on at
    RE: system.argumentnullexception value cannot be null. parameter name device credentials

    Thanks for your answers

    must i work with device credentials ?

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: system.argumentnullexception value cannot be null. parameter name device credentials

    Hello,

    You are getting this error because while connecting to CRM online you need to pass device credentials as well with your valid crm user credentials. You can use Device manager class that comes with Ms CRM SDK to register your device and get it's credentials.

    Please check this sample for your reference: msdn.microsoft.com/.../hh670628.aspx

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: system.argumentnullexception value cannot be null. parameter name device credentials

    Check these links might be helpful

    blogs.msdn.com/.../crm-2011-sdk-error-while-using-the-create-method-system-argumentnullexception-value-cannot-be-null.aspx

    nishantrana.me/.../value-cannot-be-null-parameter-name-value-error-in-crm-2011

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans