System.DirectoryServices.Protocol LDAP query results in unknown error returned from LDAP server

Viewed 1385

I am attempting to use System.DirectoryServices.Protocol to perform an LDAP query that I was able to perform successfully previously when I was using the Novell library. Specifically, I am creating the connection and binding using

_ldapConnection = new LdapConnection(
                new LdapDirectoryIdentifier(host, port, false, false),
                new NetworkCredential(userName: "CN=Administrator,CN=Users,DC=inc,DC=company,DC=com", password: "mypassword"),
                AuthType.Basic
            );
_ldapConnection.Bind();

And then doing the following query

string searchBase = "DC=inc,DC=company,DC=com";
            string filter = "(&(objectClass=person)(objectClass=user))";
            var search = new SearchRequest(searchBase, filter, SearchScope.Subtree, null);
            var response = (System.DirectoryServices.Protocols.SearchResponse)_ldapConnection.SendRequest(search, System.TimeSpan.FromMinutes(1));

However, doing so results in the following error

Unhandled exception. System.DirectoryServices.Protocols.DirectoryOperationException: An unspecified operation error occurred.
   at System.DirectoryServices.Protocols.LdapConnection.ConstructResponseAsync(Int32 messageId, LdapOperation operation, ResultAll resultType, TimeSpan requestTimeOut, Boolean exceptionOnTimeOut, Boolean sync)
   at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)

I don't understand why this is happening because as far as I can tell, I should find all the users that are people, since this says that SearchScope.Subtree should

Search the base object and all child objects. The value is equal to 2.

Any suggestions? It should be noted that If I add "CN=Users" to searchBase I am able to find users (but I don't understand why, and don't expect needing to do this since I did not need it in the Novell library. Thank you in advance for your help!

EDIT: I unpacked every property in the exception itself, and in the corresponding response attached to the exception. This is what I found:

Data: System.Collections.ListDictionaryInternal
Help Link: 
HResult: -2146233088
InnerException: 
Message: An unspecified operation error occurred.
Source: System.DirectoryServices.Protocols
StackTrace:    at System.DirectoryServices.Protocols.LdapConnection.ConstructResponseAsync(Int32 messageId, LdapOperation operation, ResultAll resultType, TimeSpan requestTimeOut, Boolean exceptionOnTimeOut, Boolean sync)
   at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)
   at Keep_LdapCore.LdapService.LogUsers() in /workspaces/Keep-LdapCore/LdapService.cs:line 35
TargetSite: Void MoveNext()
Response.Controls: System.DirectoryServices.Protocols.DirectoryControl[]
Response.Error Message: Referral:
ldap://ForestDnsZones.inc.company.com/DC=ForestDnsZones,DC=inc,DC=company,DC=com
ldap://DomainDnsZones.inc.company.com/DC=DomainDnsZones,DC=inc,DC=company,DC=com
ldap://inc.company.com/CN=Configuration,DC=inc,DC=company,DC=com
Response.MatchedDN: 
Response.Referral: System.Uri[]
Response.RequestId: 
Response.Result Code: -1
0 Answers
Related