The requested operation did not satisfy one or more constraints associated with the class of the object?

1

i have developing project in c# for creating a user in AD.

i create a user and i want to create a attribute,like "mobilenumber"for this user.

when,i create this,the below error will occured.

here my code.

      if (userDetails.GetUnderlyingObjectType() == typeof(DirectoryEntry))
        {
            dEntry = (DirectoryEntry)userDetails.GetUnderlyingObject();
            if (User.UsrPassword != null && User.UsrPassword.Trim() != "")
            {
                if (dEntry.Properties.Contains("mobilenumber"))
                {
                    Console.WriteLine("mobilenumberAttribute:Already created");
                    dEntry.Properties["mobilenumber"][0] = User.UsrPassword;
                    dEntry.CommitChanges();
                }
                else
                {
                    Console.WriteLine("mobilenumber Attribute: Adding");

                    dEntry.Properties["mobilenumber"].Add(User.UsrPassword);
                    dEntry.CommitChanges();
                }
                userDetails.Save();
                result = true;
            }
        }

The requested operation did not satisfy one or more constraints associated with the class of the object. (Exception from HRESULT: 0x80072014)

How can i resolve this?

c#
active-directory
asked on Stack Overflow Dec 6, 2012 by Sanju Monu • edited Dec 6, 2012 by Sanju Monu

1 Answer

2

Create an attribute? You mean like extending the schema? You can't do that by just adding it to an object. As you can see here, there is no such attribute as "mobilenumber". Maybe you want otherMobile (Phone-Mobile-Other) or mobile (Phone-Mobile-Primary)?

What are you trying to do? Why keep a copy of the password in the user object. If the user changes it, your copy will not be updated. If you need it to somehow inform the user, do something different like infoming his supervisor... Just a thought.

answered on Stack Overflow Dec 6, 2012 by Daro • edited Dec 6, 2012 by Daro

User contributions licensed under CC BY-SA 3.0