This question took me a lot of time to solve. First of all, the error message looks like a joke. Second, there is nothing more, just that message.
Anyway, I managed to fix it by:
Making sure that
userDn
contains the whole path (e.g.,"LDAP://server-address/CN=" + userDn + ",OU=optional,DC=your-domain,DC=com"
. This is actually very important, if you don't supply the full path it will throw an Exception from HRESULT: 0x80005000.Replacing
dirEntry.Properties["member"].Add(userDn);
byentry.Invoke("Add", new object[] { userDn });
Then I wanted to remove a user and I expected entry.Invoke("Remove", new object[] { userDn });
to work. However, this devilish AD will only work if you use lower case "remove", so entry.Invoke("remove", new object[] { userDn });
worked for me.