Binding 为什么我的DirectoryEntry突然停止工作?

Binding 为什么我的DirectoryEntry突然停止工作?,binding,active-directory,directoryservices,directoryentry,Binding,Active Directory,Directoryservices,Directoryentry,我一直在使用DirectoryServices命名空间中的DirectoryEntry对象,并且进展非常顺利。但是我对我的一个LDAP类进行了更改,它突然停止了对我的程序的32位构建的工作。 我将ActiveDs引用导入到我的项目中,以便将ADSI对象转换为适当的类型。但从那时起,我的项目在创建DirectoryEntry对象实例时无法正确绑定。 我尝试了与LDAP和WinNT提供程序绑定,但没有效果。我得到的错误是0x80005000未知错误,因为它试图绑定。 即使这个简单的代码也会失败(这并

我一直在使用DirectoryServices命名空间中的DirectoryEntry对象,并且进展非常顺利。但是我对我的一个LDAP类进行了更改,它突然停止了对我的程序的32位构建的工作。

我将ActiveDs引用导入到我的项目中,以便将ADSI对象转换为适当的类型。但从那时起,我的项目在创建DirectoryEntry对象实例时无法正确绑定。


我尝试了与LDAP和WinNT提供程序绑定,但没有效果。我得到的错误是0x80005000未知错误,因为它试图绑定。

即使这个简单的代码也会失败(这并不奇怪,因为绑定是一个关键部分!)

这有什么理由突然停止工作吗?引用会损坏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.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中的Test.Program.Main()处:第20行

这对您有用吗

        try
        {
            DirectoryEntry de = new DirectoryEntry("LDAP://server", "user", "password",  AuthenticationTypes.Secure);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
我假设“服务器”是NetBios名称?尝试使用FQDN

如果您使用自己的凭据进行绑定,则可以使用:

        DirectoryEntry de = new DirectoryEntry("LDAP://server", null, null, AuthenticationTypes.Secure);
如果您要绑定到自己的域,您可以使用:

DirectoryEntry de = new DirectoryEntry("LDAP://" + Environment.UserDomainName, null, null, AuthenticationTypes.Secure);
或者简单地说:

DirectoryEntry de = new DirectoryEntry();

我希望这会有所帮助。

任何与DirectoryEntry对象的绑定都会失败。我使用了IP地址和FQDN。还是娜达。但是,如果在Protocols命名空间中使用LdapConnection类,我可以连接到Ldap?如何:尝试{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进行绑定吗?我一直在使用LdapConnection类,但每当它需要使用DirectoryEntry实例时,它都会抛出一个异常(0x80005000)绑定时。您希望重设的对象的DN是什么?第20行是什么?您提到的更改是什么?第20行是当我尝试获取
de.Name
时。即使尝试LDAP://RootDSE,它也会失败(当我查看.NET代码时,它似乎是DirectoryEntry对象的起点)。它无法使用.NET 3.5和4.0。问题是,即使是单独的AD浏览器应用程序也无法连接。AD Explorer说我输入的服务器名不是有效的路径名,但它可以使用我的笔记本电脑工作!
DirectoryEntry de = new DirectoryEntry();