DirectoryEntry.Invoke("SetPassword", .... The directory property cannot be found in the cache

one1082 used Ask the Experts™
  I'm having trouble changing a user's password in LDAP using ASP .Net 2.0 / C#.

The LDAP server is: OpenLDAP on Red Hat 4EL.

The code is as follows:

de = new DirectoryEntry(ldapPath, ldapUsername, ldapPassword);
de.AuthenticationType = AuthenticationTypes.ServerBind;

DirectorySearcher srch = new DirectorySearcher(de);
srch.Filter = "(";

SearchResult result = srch.FindOne();

if (result != null)
     // User found, try to reset their password
          DirectoryEntry user = result.GetDirectoryEntry();
          user.Invoke("setPassword", new object[] { newPassword });

The error occurs at this line:
          user.Invoke("setPassword", new object[] { newPassword });

and returns these exceptions:
          Exception.Message = Exception has been thrown by the target of an invocation.
          Exception.InnerException.Message = The directory property cannot be found in the cache.

Thank you in advance for your help!

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®


Here's a quick info update / addition... within the LDAP, the user's password attribute is actually named "userPassword"

Would this affect how the "SetPassword" function runs?  I've also tried the "ChangePassword" function and get the same error.

I don't think it's case sensitive, but you could try:

user.Invoke("SetPassword", new object[] { newPassword });


Yeah I've tried both ways, that's not the issue.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


Still looking for some help guys!!!!

FYI:  I can get and set other items using stuff like:

user.InvokeSet("EmailAddress", new object[] { "" });

So, have you tried to set the password via InvokeSet("SetPassword", ...)... treating it as a property, rather than a method?


Returns a "Member not found" inner exception.

I've seen this problem before. The way that I've always set passwords in the past would be to use the following:

user.Invoke("SetPassword", newPassword);

you shouldn't need to create a new array for the second part because you are not using it to give the property and then the new value, you are setting the the property exactly with "SetPassword". You generally only need the Invoke method when you are doing other properties such as description which would look like this

user.Invoke("Put", new string[2]{"Description","INSERT DESCRIPTION HERE"});

This is what the password would look like using the above method (sort of what you are doing)

user.Invoke("Put", new string[2]{"SetPassword", newPassword}); /* SetPassword may not be the actual way, but this is just a reference- not the best way to do it */

Hope this helps

Forced accept.

EE Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial