ASP.Net C# and Active Directory error "c# index was out of range. Must be nonnegative and less than the size of the collection"

hello Experts,

I have a bit of code that binds to on Active Directory user, disable it, and move it to  a cleanup OU. I tried to add a line of code that will write to the description attriubute on the object, but I keep getting the error "c# index was out of range. Must be nonnegative and less than the size of the collection", once the code reaches userMove.Properties["description"][0] .
Below is a snipped of the code"

                                try
                                {
                                    AccDisable ad = new AccDisable();
                                    ad.Disable(userDN);
                                // Bind to the object to be moved.
                                    DirectoryEntry userMove = new DirectoryEntry("LDAP://" + userDN, systemUser, systemPw);
                                    // Update the Description attribute on the user
                                    userMove.Properties["description"][0] = "no NASW Authentication has taken place in the past" + dayCreatRound;
                                  

                                // Use the MoveTo property to define the new container you want to move the object to.
                                   // userMove.MoveTo(new DirectoryEntry("LDAP://OU=OVER_45_DAYS_USER,OU=CLEANUP,OU=domain.com", systemUser, systemPw));                           
                                }
                                catch (InvalidOperationException InvOpEx)
                                {
                                    // Handle InvalidOperationException.
                            
                                    string messageEx = "Could not move "+InvOpEx.Message;
                                    lm.WriteLogNoDS(messageEx,logLocation);
                                }
                                catch ( Exception Ex)
                                {
                                    // Handle all other errors
                                    string messageEx = "Could not move " + Ex.Message;
                                    lm.WriteLogNoDS(messageEx, logLocation);
                                }
                                #endregion
                            }

Open in new window

LVL 3
karephreIT Specialist (Server Management)Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

karephreIT Specialist (Server Management)Author Commented:
Hello Experts,

I found my issue I change the the below code to make it work:

userMove.Properties["description"].Value = "no NASW Authentication has taken place in the past" + dayCreatRound;
                                    userMove.CommitChanges();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
karephreIT Specialist (Server Management)Author Commented:
Change my code to value, then commited the changes.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.