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)

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)
  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    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

  • yosra.walid Profile Picture
    on at

    Thanks for your answers

    must i work with device credentials ?

  • yosra.walid Profile Picture
    on at

    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

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    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

    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"

  • yosra.walid Profile Picture
    on at

    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

    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

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