How to get rid of DirectoryServicesCOMException while searching in Active Directory using C#?

0

I know how to fetch data from Active Directory using C# and System.DirectoryService. I have a sample here:

var rootEntry = new DirectoryEntry("LDAP://mydomain.local", "UserName", "Password");
var searcher = new DirectorySearcher(rootentry);
searcher.CacheResults = false;
searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;
searcher.PageSize = 1000;
searcher.Filter = "Some LDAP Query";
searcher.PropertiesToLoad.AddRange(new[] { "objectguid", "name", "objectclass" });
var result = searcher.FindAll();
var enumerator = result.GetEnumerator();
while (enumerator.MoveNext())  // THIS LINE THROWS AN EXCEPTION
{
   // Do my work here
}

However enumerator.MoveNext() throws an exception most of the time but not everytime. Details of the exception are given as follows:

System.DirectoryServices.DirectoryServicesCOMException (0x8007202C): The server does not support the requested critical extension.

at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()

Unfortunately, I am unable to figure the conditions under which the exception is thrown. Please help me out here! How can I get rid of this exception?

Thanking in advance.

PS: I have viewed the following StackOverflow articles but those do not answer my particular question.

fetch active directory user data using C#

How to Search User in Active Directory using LDAP in Asp.net C#

I am not an Active Directory expert so please don't assume any knowledge. Thanks!

I am trying to execute the following LDAP Query:

(&(!cn=SystemMailbox{e0dc1c29-89c3-4034-b678-e6c29d823ed9})(!cn=SystemMailbox{1f05a927-f7a0-4bff-ba0e-7400efadb1d7})(!cn=FederatedEmail.4c1f4d8b-8179-4148-93bf-00a95fa1e042)(!cn=DiscoverySearchMailbox{D919BA05-46A6-415f-80AD-7E09334BB852})(!cn=SystemMailbox{1f05a927-fb80-4c7c-8a53-b072e381d13a})(!cn=SystemMailbox{bb558c35-97f1-4cb9-8ff7-d53741dc928c})(!cn=Migration.8f3e7716-2011-43e4-96b1-aba62d229136)(!cn=SystemMailbox{1f05a927-594f-4c55-a9ca-99486880acb5})(!cn=SystemMailbox{1f05a927-1b66-4473-9aec-cf049b8cef3d})(!cn=SystemMailbox{D0E409A0-AF9B-4720-92FE-AAC869B0D201})(!cn=SystemMailbox{2CE34405-31BE-455D-89D7-A7C7DA7A0DAA})(!cn=SystemMailbox{1f05a927-9350-4efe-a823-5529c2d64109})(!cn=SystemMailbox{1f05a927-c92b-414e-aeb0-1256cedb2cfb})(!cn=SystemMailbox{8cc370d3-822a-4ab8-a926-bb94bd0641a9})(!cn=SystemMailbox{1f05a927-eac1-46e7-9a47-611e1a81bb50})(!cn=SystemMailbox{1f05a927*)(|(&(objectClass=user)(objectCategory=person))(objectClass=group)(&(objectClass=contact)(objectCategory=person))(&(objectClass=publicFolder)(objectCategory=publicFolder))(&(objectClass=computer)(objectCategory=computer))(objectCategory=container)(objectCategory=domain)(objectCategory=organizationalUnit))(!name=System)(!name=Microsoft Exchange System Objects)(!name=ForeignSecurityPrincipals))
c#
active-directory
asked on Stack Overflow Oct 8, 2020 by arslanahmad656 • edited Oct 8, 2020 by arslanahmad656

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0