开发者

Exception in Directory Entry

开发者 https://www.devze.com 2023-03-17 01:13 出处:网络
I create new DirectoryEntry and I have exception in it (system.runtime.interopservices.comexception).

I create new DirectoryEntry and I have exception in it

(system.runtime.interopservices.comexception).

Previous DirectoryEntry is open ok (directoryEntry).

In directoryEntry.Properties["manager"].Value is correct value.

using (DirectoryEntry manager = new DirectoryEntry(Convert.ToString(directoryEntry.Properties["ma开发者_如何学Cnager"].Value)))
{                
   contact.ManagersGuid = manager.NativeGuid;
}

Do you know where could be a problem? More opened directory entries in same moment?


What is stored in Properties["manager"].Value ? My hunch is: that's not a complete, valid LDAP path......

If my hunch is correct, then you're not getting back a valid DirectoryEntry for the manager.

Try this code instead:

string manager = directoryEntry.Properties["manager"].Value.ToString();

// check what is stored in "manager" ! It needs to be a **full** LDAP path
// something like `LDAP://..........`

using (DirectoryEntry manager = new DirectoryEntry(manager))
{
   try
   {
      contact.ManagersGuid = manager.NativeGuid;
   }
   catch(Exception ex)
   {
       // log and handle the exception, if something goes wrong....
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消