Let's say I have this LDAP path and I want to search for an object in AD using System.DirectoryServices.DirectoryEntry:
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?