2011-07-02 59 views
1

我创造新的DirectoryEntry和我有它异常在目录条目

(system.runtime.interopservices.comexception)例外。

上一个DirectoryEntry是开放的(directoryEntry)。

directoryEntry.Properties["manager"].Value是正确的值。

using (DirectoryEntry manager = new DirectoryEntry(Convert.ToString(directoryEntry.Properties["manager"].Value))) 
{     
    contact.ManagersGuid = manager.NativeGuid; 
} 

你知道哪里可能会出现问题吗?同一时刻更多打开的目录条目?

+1

什么是在异常的详细信息? –

+0

消息:未指定(不完全是此术语,我已将其本地化为另一种语言) –

回答

2

什么是存储在Properties["manager"].Value?我的直觉是:这不是一个完整的,有效的LDAP路径......

如果我的预感是正确的,那么你就别想回来管理者的有效DirectoryEntry

试试这个代码,而不是:

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

directoryEntry.Properties [“manager”]。值必须重新键入为字符串。我不知道为什么,但在调试它是对象。更改后键入字符串是正确的LDAP路径。 –