Home > Net >  LdapConnection SearchRequest throwing object does not exist error - revisited
LdapConnection SearchRequest throwing object does not exist error - revisited

Time:02-11

I have the same question as in LdapConnection SearchRequest throwing object does not exist error. The answer over there doesn't seem to work for me.

Whenever these two lines of code are executed (Winforms app, C#)...

var request = new SearchRequest(DN, "(objectClass=*)", SearchScope.Subtree, null);
var response = (SearchResponse)LdapConnection.SendRequest(request);

...and DN points to an existing distinguished name, everything works fine. If DN does not point to an existing distinguished name, I get an "Object does not exist" error instead of a valid SearchResponse object with .Entries.Count == 0. I cannot change the filter parameter, this has to be "(objectClass=*)" (in case that would make any difference; it is different the Stackoverflow post that I refer to).

Anyone any ideas?

CodePudding user response:

That's expected behaviour.

The DN you're providing is the search root: the location in the directory to start the search. If that is invalid, then it can't perform the search, which is why you get an exception.

That is different than a case where the search is successfully performed, but no results are found.

If you can't verify ahead of time if the DN exists, then just catch that exception.

  • Related