2011-07-02 56 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路徑。 –