After many days of searching, I find the problem. when you add a user to a group, you must set the "distinguished name" and not the LDAP path.
You should write like this:
ent.Properties["member"].Add("CN=YourUserName,OU=optional,DC=yourdomain,DC=com");
This is the wrong code:
ent.Properties["member"].Add("LDAP://CN=YourUserName,OU=optional,DC=yourdomain,DC=com");
Also, when you remove the mast to save this rule
ent.Properties["member"].Remove("CN=YourUserName,OU=optional,DC=yourdomain,DC=com");
PS ent is a DirectoryEntry group object
Tornike chuchulashvili
source share