2

I'm trying to create a user and add it to 3 groups, the creation is working properly but adding user to groups sometimes it's working and sometimes show this error:

there is no such object on the server

my code for adding user to group :

try
            {
                DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + group, ADUsername, ADPassword);
                if (dirEntry != null)
                {
                    dirEntry.Properties["member"].Add(userPrincipal.DistinguishedName);
                    dirEntry.CommitChanges();
                    dirEntry.Close();
                }
            }
            catch (System.DirectoryServices.DirectoryServicesCOMException E)
            {
                //doSomething with E.Message.ToString();

            }
1

1 Answer 1

2

I have experienced this and in my situation it was because the newly created object hadn’t replicated to all of our DCs. I resolved this by introducing a 3 second delay after I created the user. I then proceeded with adding the user to the groups.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this has been my first thought too after reading this question. Some developers don't like sleeps (sometimes for good reason), but real life requires this in some situations :-) Perhaps only 1 sec delay and using a retry loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.