locked
system.argumentnullexception value cannot be null. parameter name device credentials RRS feed

  • Question

  • 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" 

    iwant work without DeviceCredentials , 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
    Tuesday, March 24, 2015 4:14 PM