Click here to Skip to main content
15,924,318 members
Home / Discussions / C#
   

C#

 
AnswerRe: threads and acknowledgment Pin
Luc Pattyn15-Apr-07 22:10
sitebuilderLuc Pattyn15-Apr-07 22:10 
AnswerRe: threads and acknowledgment Pin
pbraun16-Apr-07 5:16
pbraun16-Apr-07 5:16 
QuestionWorkerEventHandler.BeginInvoke() questions. Pin
Are Jay15-Apr-07 18:26
Are Jay15-Apr-07 18:26 
AnswerRe: WorkerEventHandler.BeginInvoke() questions. Pin
Luc Pattyn16-Apr-07 4:06
sitebuilderLuc Pattyn16-Apr-07 4:06 
GeneralRe: WorkerEventHandler.BeginInvoke() questions. Pin
Are Jay16-Apr-07 4:54
Are Jay16-Apr-07 4:54 
GeneralRe: WorkerEventHandler.BeginInvoke() questions. Pin
Luc Pattyn16-Apr-07 6:49
sitebuilderLuc Pattyn16-Apr-07 6:49 
GeneralRe: WorkerEventHandler.BeginInvoke() questions. Pin
Are Jay20-Apr-07 13:40
Are Jay20-Apr-07 13:40 
QuestionObject Reference not Set an instance of an object while Querying the 2003 Active Directory Pin
Zach198315-Apr-07 17:28
Zach198315-Apr-07 17:28 
Hi,

I have an wierd exception raised in my code when I query the 2003 Acitve Directory for the User information.

I am getting an Exception in the line

'ResultPropertyCollection props = srResult.Properties'

which says 'Object Refernece not set to an instance of an object'

but the same code works fine with a test page what i created...and even the same code works fine with windows 2000 server which is now in Production.

I would really appreciate some kind of help with this..



// constructor
public UserInfo(UserDirectory parentDirectory, String userAttribute, UserSearchType searchType)
{
if (parentDirectory != null)
{
DateTime LDAPStarted = DateTime.Now;
try
{
Directory = parentDirectory;
String filter = "(SAMAccountName=" + userAttribute + ")";
if (searchType == UserSearchType.Email)
filter = "(mail=" + userAttribute + ")";
if (searchType == UserSearchType.LegacyExchangeDN)
filter = "(legacyExchangeDN=" + userAttribute + ")";
if (searchType == UserSearchType.DistinguishedName)
filter = "(distinguishedName=" + userAttribute + ")";

logger.LogDebug(String.Format("UserInfo ({0},{1},{2}). filter={3}", parentDirectory, userAttribute, searchType, filter));
logger.LogDebug(String.Format("LDAP - Server:{0}, Domain:{1}, UserName:{2}", Directory.Configuration.LDAPServer, Directory.Configuration.LDAPDomain, Directory.Configuration.LDAPUsername));

DirectoryEntry deRootDSE;
DirectoryEntry deDomain;
DirectorySearcher dsSearcher;
SearchResult srResult;
deRootDSE = new DirectoryEntry("LDAP://" + Directory.Configuration.LDAPServer + "/RootDSE",
Directory.Configuration.LDAPDomain + "\\" +
Directory.Configuration.LDAPUsername,
Directory.Configuration.LDAPPassword,
AuthenticationTypes.ServerBind);
deDomain = new DirectoryEntry("LDAP://" + Directory.Configuration.LDAPServer + "/" +
deRootDSE.Properties["defaultNamingContext"].Value.ToString(),
Directory.Configuration.LDAPDomain + "\\" +
Directory.Configuration.LDAPUsername,
Directory.Configuration.LDAPPassword,
AuthenticationTypes.ServerBind);

dsSearcher = new DirectorySearcher();
dsSearcher.SearchRoot = deDomain;
dsSearcher.Filter = filter;
dsSearcher.SearchScope = SearchScope.Subtree;
dsSearcher.PropertiesToLoad.Add("cn");
dsSearcher.PropertiesToLoad.Add("sn");
dsSearcher.PropertiesToLoad.Add("canonicalName");
dsSearcher.PropertiesToLoad.Add("displayName");
dsSearcher.PropertiesToLoad.Add("distinguishedName");
dsSearcher.PropertiesToLoad.Add("givenName");
dsSearcher.PropertiesToLoad.Add("name");
dsSearcher.PropertiesToLoad.Add("homeMDB");
dsSearcher.PropertiesToLoad.Add("homeMTA");
dsSearcher.PropertiesToLoad.Add("mail");
dsSearcher.PropertiesToLoad.Add("mailNickname");
dsSearcher.PropertiesToLoad.Add("proxyAddresses");
dsSearcher.PropertiesToLoad.Add("sAMAccountName");
dsSearcher.PropertiesToLoad.Add("userPrincipalName");
dsSearcher.PropertiesToLoad.Add("legacyExchangeDN");
dsSearcher.PropertiesToLoad.Add("objectclass");
dsSearcher.PropertiesToLoad.Add("member");
srResult = dsSearcher.FindOne();
ResultPropertyCollection props = srResult.Properties;
HomeMDB = GetDefaultPropValue(props, "homeMDB", "localhost");
DirectoryEntry deHomeMDB = new DirectoryEntry("LDAP://" + HomeMDB);
SAMAccountName = GetDefaultPropValue(props, "sAMAccountName", PROP_NA);
CN = GetDefaultPropValue(props, "cn", PROP_NA);
SN = GetDefaultPropValue(props, "sn", PROP_NA);
CanonicalName = GetDefaultPropValue(props, "canonicalName", PROP_NA);
DisplayName = GetDefaultPropValue(props, "displayName", PROP_NA);
DistinguishedName = GetDefaultPropValue(props, "distinguishedName", PROP_NA);
GivenName = GetDefaultPropValue(props, "givenName", PROP_NA);
Name = GetDefaultPropValue(props, "name", PROP_NA);
HomeMTA = GetDefaultPropValue(props, "homeMTA", PROP_NA);
Mail = GetDefaultPropValue(props, "mail", PROP_NA);
MailAlias = Mail.Substring(0, Mail.IndexOf("@"));
MailNickname = GetDefaultPropValue(props, "mailNickname", PROP_NA);
ProxyAddresses = GetDefaultPropValue(props, "proxyAddresses", PROP_NA);
UserPrincipalName = GetDefaultPropValue(props, "userPrincipalName", PROP_NA);
LegacyExchangeDN = GetDefaultPropValue(props, "legacyExchangeDN", PROP_NA);
objectClasses = GetPropValues(props, "objectclass");
memberDistinguishedNames = GetPropValues(props, "member");

StoreURL = Directory.Configuration.StoreURI;
StoreURL = StoreURL.Replace("%EXCHANGE_SERVER%", OwningServer);
StoreURL = StoreURL.Replace("%MAILALIAS%", MailAlias);
StoreURL = StoreURL.Replace("%USERNAME%", SAMAccountName);

if (Directory.Configuration.StoreCredentialType.Equals(ConfigInfo.CredentialTypes.Personal))
{
//derive the domain
char[] commadelim = { ',' };
string[] splitPath = DistinguishedName.Split(commadelim);
string domain = null;
foreach (string path in splitPath)
{
char[] eqdelim = { '=' };
string[] splitvalue = path.Split(eqdelim);
if (splitvalue.Length > 1 && splitvalue[0] != null && splitvalue[0].Equals("DC") && splitvalue[1] != null)
{
if (domain != null)
domain += ".";
domain += splitvalue[1];
}
}
authDomain = domain;
DomainPasswordPair dpp = Directory.Credentials.Recall(SAMAccountName);
authUser = SAMAccountName;
authPassword = dpp.Password;
Directory.Credentials.Cache(SAMAccountName, authDomain, authPassword);
}
else
{ // Store Credential Type is Universal - use the common user and password
authDomain = Directory.Configuration.StoreDomain;
authUser = Directory.Configuration.StoreUsername;
authPassword = Directory.Configuration.StorePassword;
}
Statistics.Add(6, Directory.Configuration.ConfigName, LDAPStarted, (DateTime.Now.Ticks - LDAPStarted.Ticks) / 10000, 1, true, "SUCCESS", null);
}
catch (System.Runtime.InteropServices.COMException ce)
{
throw new Exception("FATAL: COM Exception while trying to retrieve User Info from LDAP: {" + ce.Message + "}");
}
}
else
throw new Exception("FATAL: UserInfo requires a valid User Directory instance.");
} // public UserInfo(UserDirectory parentDirectory, String userName, UserSearchType searchType)



Thanks

Zach1983
AnswerRe: Object Reference not Set an instance of an object while Querying the 2003 Active Directory Pin
Luc Pattyn16-Apr-07 4:10
sitebuilderLuc Pattyn16-Apr-07 4:10 
GeneralRe: Object Reference not Set an instance of an object while Querying the 2003 Active Directory Pin
Zach198316-Apr-07 8:27
Zach198316-Apr-07 8:27 
GeneralRe: Object Reference not Set an instance of an object while Querying the 2003 Active Directory Pin
Luc Pattyn16-Apr-07 8:58
sitebuilderLuc Pattyn16-Apr-07 8:58 
QuestionRe: Object Reference not Set an instance of an object while Querying the 2003 Active Directory Pin
Zach198318-Apr-07 10:13
Zach198318-Apr-07 10:13 
QuestionRe: Object Reference not Set an instance of an object while Querying the 2003 Active Directory Pin
Zach198318-Apr-07 10:22
Zach198318-Apr-07 10:22 
AnswerRe: Object Reference not Set an instance of an object while Querying the 2003 Active Directory Pin
Luc Pattyn18-Apr-07 14:04
sitebuilderLuc Pattyn18-Apr-07 14:04 
QuestionHelp selecting xml nodes Pin
drifters15-Apr-07 17:02
drifters15-Apr-07 17:02 
AnswerRe: Help selecting xml nodes Pin
Christian Graus15-Apr-07 17:36
protectorChristian Graus15-Apr-07 17:36 
GeneralRe: Help selecting xml nodes Pin
drifters15-Apr-07 17:42
drifters15-Apr-07 17:42 
QuestionWindow Focus Pin
dirkwilliams15-Apr-07 16:03
dirkwilliams15-Apr-07 16:03 
AnswerRe: Window Focus Pin
Luc Pattyn15-Apr-07 23:16
sitebuilderLuc Pattyn15-Apr-07 23:16 
QuestionQuestion about detecting mouse click using? Pin
Khoramdin15-Apr-07 15:31
Khoramdin15-Apr-07 15:31 
AnswerRe: Question about detecting mouse click using? Pin
Christian Graus15-Apr-07 16:54
protectorChristian Graus15-Apr-07 16:54 
GeneralRe: Question about detecting mouse click using? Pin
Khoramdin16-Apr-07 6:29
Khoramdin16-Apr-07 6:29 
QuestionmyCommand.SelectCommand.Parameters.Add(new SqlParameter("@State", SqlDbType.NVarChar, 1)); Pin
swjam15-Apr-07 14:09
swjam15-Apr-07 14:09 
AnswerRe: myCommand.SelectCommand.Parameters.Add(new SqlParameter("@State", SqlDbType.NVarChar, 1)); Pin
Christian Graus15-Apr-07 15:19
protectorChristian Graus15-Apr-07 15:19 
QuestionSave Mesh data to a .X file Pin
max2929715-Apr-07 13:06
max2929715-Apr-07 13:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.