【发布时间】:2012-03-29 12:37:28
【问题描述】:
我一直在使用 DirectoryServices 命名空间中的 DirectoryEntry 对象,并且进展顺利。但是我对我的一个 LDAP 类进行了更改,突然间它停止了在我的程序的 32 位版本上工作。
我将 ActiveDs 引用导入到我的项目中,以便将 ADSI 对象转换为其适当的类型。但从那时起,我的项目在创建 DirectoryEntry 对象的实例时未能正确绑定。
我曾尝试与 LDAP AND WinNT 提供程序绑定,但无济于事。我得到的错误是尝试绑定时出现 0x80005000 未知错误。
即使是这个简单的代码也会失败(这并不奇怪,因为绑定是一个关键部分!)
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,但它只是挂起。
Daro 建议的结果:
代码
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.DirectoryServices.DirectoryEntry.Bind(布尔 throwIfFail)
在 System.DirectoryServices.DirectoryEntry.Bind()
在 System.DirectoryServices.DirectoryEntry.get_Name()
在 C:\Users\#username#\Documents\Visual Studio 2010\Projects\#project#\Test\Program.cs:line 20 中的 Test.Program.Main()
【问题讨论】:
标签: binding active-directory directoryservices directoryentry