AD throws COMException with Error Code -2147463168

0
Unbekannter Fehler (0x80005000) bei System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
bei System.DirectoryServices.DirectoryEntry.Bind()
bei System.DirectoryServices.DirectoryEntry.get_AdsObject()
bei System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
bei System.DirectoryServices.DirectorySearcher.FindAll() 

this is what is returned. My code looks like:

string domain = DNFilterEntry.Key;
DirectoryEntry entry = new DirectoryEntry("LDAP://" + ((domain != "") ? "DC=" + domain : ""));
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.PropertiesToLoad.Add("displayName");
searcher.PropertiesToLoad.Add("mail");
searcher.Filter = string.Format("(|"+DNfilterEntry.Value+")",filterparams.ToArray());
try
{
    SearchResultCollection users = searcher.FindAll(); // error thrown here
    ...
}
catch (System.Runtime.InteropServices.COMException ex) { Debug.Message(ex.ErrorCode + ex.Message + ex.StackTrace); continue; }

The Key-Value-Pair DNfilterEntry is "" => "(mail={0})(mail={1})"

and filterparams is a List containing two items somemail@intra.domain.com and someothermail@intra.domain.com. The filter is generated correctly to

(mail=somemail@intra.domain.com)(mail=someothermail@intra.domain.com)

(proven with VS debugger; and both mail adresses are valid)

Anyone here knows why that error occurs?

EDIT: The following code for a different query works out without error:

string Filter="(&";
switch (filterType) {
    case 0: Filter += "(sAMAccountType=805306368)"; break;
    case 1: Filter += "(objectCategory=group)"; break;
    case 2: Filter += "(|(objectCategory=group)(objectCategory=person))"; break;
}
Filter += "(sAMAccountName={0}))";
DirectorySearcher searcher = new DirectorySearcher();
searcher.Filter = string.Format(Filter, username);
SearchResult user = searcher.FindOne();
if (user == null || user.Properties == null || user.Properties[propName] == null || user.Properties[propName][0] == null) return null;
return user.Properties[propName][0].ToString();

with propName = "mail", username="someusername", domain="", filterType=0 it returns the primary email adress of someusername.

EDIT2:

Can someone tell me why it works when I change DirectorySearcher searcher = new DirectorySearcher(entry); into DirectorySearcher searcher = new DirectorySearcher();

c#
active-directory
comexception
asked on Stack Overflow Nov 25, 2013 by Alexander • edited Nov 25, 2013 by Alexander

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0