DirectoryEntry.Invoke() throws error on "ChangePassword" call

4

DirectoryEntryObject.Invoke("ChangePassword", new object[] { oldPassword, newPassword } ); throws the following error:

"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Runtime.InteropServices.COMException (0x80020005): Type mismatch.
(Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
--- End of inner exception stack trace ---
at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)

Is this something to do with any settings in the AD or I am missing anything?

c#
active-directory
asked on Stack Overflow Jul 30, 2010 by Ashish Gupta • edited Jul 30, 2010 by marc_s

1 Answer

0

There's an MSDN page titled Managing User Passwords that has some examples of how to call ChangePassword from C#. The specific sample shows the following syntax:

usr.Invoke("ChangePassword", OldSecurelyStoredPassword, NewSecurelyStoredPassword);

I suspect it's because you're calling it and passing in an object array, rather than passing two strings explicitly (the documentation you've linked to in your comment indicates that it expects to be passed two strings, one as an input parameter and one as an output parameter. Try this:

var oldPassword = "TheOldPassword";
var newPassword = "TheNewPassword";
DirectoryEntryObject.Invoke("ChangePassword", oldPassword, newPassword);
answered on Stack Overflow Jul 30, 2010 by Rob

User contributions licensed under CC BY-SA 3.0