Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Let's say I have this LDAP path and I want to search for an object in AD using System.DirectoryServices.DirectoryEntry:

C#
var path = "LDAP://test.com/CN=bob,OU=Users,DC=test,DC=com"

This path was retrieved from AD 1 minute ago. What if the object was deleted that second or the connection to Active Directory dropped.
In my application, i stored this path, and I want to change one of the attributes of that object. So, I retrieve the path and do whatever I want. In both cases, deleted object or no connection, I get the same Exception
"System.Runtime.InteropServices.COMException"


I want to throw an exception stating the problem, how do I distinguish between both cases?
I want to do this because, in case it was a connection problem, i want to try again after a specific amount of time. However if the object is deleted, I want my Application user to know this.

What I have tried:

DirectoryEntry Constructor does not do any kind of validation. In Addition, DirectoryEntry.Exsist(path) returns false, but does not give additional information.
Any Suggestions?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900