我一直在使用DirectoryServices命名空間中的DirectoryEntry對象,它一直很好。但是我修改了其中一個LDAP類,並突然停止了32位版本的程序工作。
我將ActiveDs引用導入到我的項目中,以便將ADSI對象轉換爲適當的類型。但從那時起,我的項目在創建DirectoryEntry對象實例時無法正確綁定。
我已經嘗試綁定與LDAP和WinNT提供程序,但無濟於事。我得到的錯誤是0x80005000未知錯誤,因爲它試圖綁定。
即使這樣簡單的代碼失敗(這並不奇怪,因爲綁定是一個重要組成部分!)
爲什麼我的DirectoryEntry突然停止工作?
static void Main(string[] args)
{
try
{
using(var de = new DirectoryEntry("LDAP://servername", "user", "password", AuthenticationType.Secure)
{
Console.WriteLine(de.Name)
}
}
catch(Exception ex)
{
Console.WriteLine(ex)
}
}
是否有任何理由爲什麼這應該突然停止工作?一個引用是否可以破壞32位機器上已有的DLL?
注意:
我也嘗試使用VBS腳本查詢LDAP,但它只是掛起。從達羅的建議
結果:
代碼
static void Main()
{
try
{
using (var ldap = new LdapConnection(new LdapDirectoryIdentifier("ad1")))
{
ldap.Bind();
using (var de = new DirectoryEntry("LDAP://" + ldap.SessionOptions.DomainName))
{
Console.WriteLine(de.Name);
}
}
}
catch(Exception ex)
{
using(var fs = new FileStream("C:\\error.log", FileMode.Create, FileAccess.Write))
{
using(var sw = new StreamWriter(fs))
{
sw.WriteLine(ex.Message);
sw.WriteLine(ex.StackTrace);
}
}
}
日誌文件產生:
未知錯誤(0x80005000)
在System.Di rectoryServices.DirectoryEntry.Bind(布爾throwIfFail)
在System.DirectoryServices.DirectoryEntry.Bind()
在System.DirectoryServices.DirectoryEntry.get_Name()
在Test.Program.Main()在C:\ Users \用戶#用戶名#\ Documents \ Visual Studio 2010 \ Projects \#項目#\ Test \ Program.cs:第20行
與DirectoryEntry對象的任何綁定失敗。我已經使用IP地址和FQDN。仍然是納達。 但是,如果我在Protocols命名空間中使用LdapConnection類,則可以連接到Ldap。 – mrstebo 2012-03-30 09:09:38
因此,我發佈的代碼位導致相同的錯誤?如何:嘗試 LdapConnection lc = new LdapConnection(Environment.UserDomainName); lc.Bind(); DirectoryEntry de = new DirectoryEntry(「LDAP://」+ lc.SessionOptions.DomainName); string Name = de.Name; } catch(Exception ex) { Console.WriteLine(ex); } 你可以綁定使用ldp.exe? – Daro 2012-03-30 11:30:54
我一直在使用LdapConnection類,但無論何時需要使用DirectoryEntry實例,它都會在綁定時引發異常(0x80005000)。 – mrstebo 2012-04-02 08:52:41