Skip to main content
object reference not found exception message is thrown when i attempt to invoke GetDomains method.

Here is the code im using:


public string getDomainNames()
{
K2Manager myK2Mgr=new K2Manager();
StringBuilder strDomainNames=new StringBuilder();
int count=0;

try
{
Domains myDomains=myK2Mgr.GetDomains();
count=myDomains.Count;
foreach(Domain myDomain in myDomains)
{
strDomainNames.Append(myDomain.Name);
strDomainNames.Append('|');
}
return strDomainNames.ToString()+" "+count;
}
catch(Exception ex)
{
ex.ToString();
return ex.Message+" "+count;
}
}


myDomains.Count property returns the exception obj ref not set

Im running a development machine which has k2 studio and k2service manager installed in it (k2.net 2003 SP 3).

My machine connects to a domain server in which ADS is installed and it is configured as my k2server.

I studied the Help doc and searched for the K2server.config file it has the following tags in my local machine.


<K2Server>
<Database/>
<LogDatabase/>
<DefaultSMTPServer/>
</K2Server>


whereas in my domain server/K2server it has appropriate values for all the tags.

the code given by me above, im using it in an asp.net web application, which is in my development machine. I have configured the virtualdirectory security settings as follows

allow iis to manage passwords==false
anonymous access == enabled
anonymous user account: An user account in ADS.

I get the myDomains object returning null reference.Hope someone Can help me solve my problem. Please explain whats happening and why i get this error.

thanks to you all
You need to call the 'Login' method of the K2Manager class first.

HTH,
Ockert
thanks and i try the thing
Hi Ockert I performed a search before posting the issue and i got this:


Magic!!

Certain functions in K2Mng namely GetDomains, GetGroups and GetUsers has been exposed and can be called without physically logging in on K2Mng. The only requirement is that the user making the call should be an authenticated domain user.



this was your reply. Still i have not tried it out(calling the login method) but please explain what does it mean:
Certain functions in K2Mng namely GetDomains, GetGroups and GetUsers has been exposed and can be called without physically logging in on K2Mng.

thanks for your reply

Hi Ockert thanks for your advice and it works fine after calling login.

My doubts are:
1. To Login to the system i need the domain name but here iam listing the domain names after i am logged in, but seems something odd.

My observations are:
1.since getDomains method gets the domain objects from the configuration settings it seems there is no logic in populating the domain names to the users without the caller loging in to the server.

. I am trying to populate the domains applicable in the network and provide them in a dropdown list for the users in the login screen itself to select their allowed domains.

as i took a look into the k2mng namespace and getdomains method I thought i could do as desired (may be my thought is weird). but hope I shall find some ways in the directoryservices.dll.

....thiru

Reply