Why has my DirectoryEntry stopped working suddenly?

1

I have been working with the DirectoryEntry objects in the DirectoryServices namespace and it has been going very well. But I made changes to one of my LDAP classes and all of a sudden it has stopped working on the 32 bit builds of my program.

I imported the ActiveDs reference into my project in order to convert the ADSI objects to their appropriate types. But since then my projects are failing to bind correctly when creating instances of the DirectoryEntry object.


I have tried binding with the LDAP AND WinNT provider but to no avail. The error I get is the 0x80005000 unknown error as it tries to bind.

Even this simple code fails (which is not surprising as binding is a critical part!)

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)
    }
}

Is there any reason why this should suddenly stop working? Could a reference corrupt an already existing DLL on a 32 bit machine?

Note:
I have also tried querying LDAP using a VBS script but it just hangs.


Results from Daro's suggestion:
code

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);
            }
        }
    }



The log file produces:
Unknown error (0x80005000)
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_Name()
at Test.Program.Main() in C:\Users\#username#\Documents\Visual Studio 2010\Projects\#project#\Test\Program.cs:line 20

binding
active-directory
directoryservices
directoryentry
asked on Stack Overflow Mar 29, 2012 by mrstebo • edited Apr 2, 2012 by mrstebo

1 Answer

0

Does this work for you?

        try
        {
            DirectoryEntry de = new DirectoryEntry("LDAP://server", "user", "password",  AuthenticationTypes.Secure);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }

I assume "Server" is the NetBios name? Try using the FQDN.

If your binding with your own credentials, you can use:

        DirectoryEntry de = new DirectoryEntry("LDAP://server", null, null, AuthenticationTypes.Secure);

And if you are binding to your own domain, you could use:

DirectoryEntry de = new DirectoryEntry("LDAP://" + Environment.UserDomainName, null, null, AuthenticationTypes.Secure);

or simply:

DirectoryEntry de = new DirectoryEntry();

I hope that helps.

answered on Stack Overflow Mar 30, 2012 by Daro

User contributions licensed under CC BY-SA 3.0