views:

149

answers:

1

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?

A: 

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);
Rob
@Rob, there is another MSDN page http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.invoke.aspx. And this Invoke() method takes object[]. This is used by few other applications in the company as well. I am not sure why this won't work.
ydobonmai
@Ashish, that's all well and good, but *have you tried what myself and Lasse have suggested?* AND, are you saying you have code in other applications that Invokes the **ChangePassword** method, passing in an object array and that *does* work?
Rob
@Rob, "are you saying you have code in other applications that Invokes the ChangePassword method, passing in an object array and that does work?"the answer is "yes".
ydobonmai
And what about "have you tried what myself and Lasse have suggested?" ?
Rob
@Rob, I will definitely give that a shot.
ydobonmai