[LDAP] Error creating users - Cannot access a disposed object.

[LDAP] Error creating users - Cannot access a disposed object.

  
Forge Component
(15)
Published on 2014-11-24 by Filipe Jacinto
15 votes
Published on 2014-11-24 by Filipe Jacinto

Whenever I try to use a write operation (like) create user r create group, I get this error:

Cannot access a disposed object.
Object name: 'DirectoryEntry'.

I was able to go around this by disabling part of the code that I think is causing the error: the getValidDirectoryEntry method in the extension is disposing  the newly created object before returning it. This doesn't make much sense to me, but wanted to check with you if if it's really a bug.

Hi João,


  Thanks for sharing. If you could post the code snippet that you deleted I will update the extension.


Best Regards,

André Pereira

Hi André, thanks for you reply


The snippet I changed is this one, it was closing and disposing the object before returning it: 


protected DirectoryEntry getValidDirectoryEntry(string ssPath,
            string ssUsername, string ssPassword)
        {
            DirectoryEntry e = new DirectoryEntry(ssPath, ssUsername, ssPassword);

            try
            {
                if (e.Name == "") throw new Exception();
            }
            catch (Exception)
            {
                throw new Exception("Could not find usable entry in path");
            }


            return e;
        }


I also attached the updated extension.


Thanks!