Bugs and Feature Requests

Coordinator
Apr 12, 2012 at 8:32 PM

This section provides a way of reporting bugs and requesting new features.

Aug 2, 2012 at 8:41 PM

I have a bug with the AddObject and the SetPassword methods, i made my own context and my own entities.

When i add a new User it works, but the firstname, username, email and password aren't saved (the firstname is saved but it's something like : $431000-N36ODG05FT1H) I can't set his password with the SetPassword method, i get an error : HRESULT : 0x80070544.

 

Any idea?

Coordinator
Aug 3, 2012 at 7:35 AM

Sure, can you give me a little info of how you are trying to save the user? I would need the attributes on the user properties and the method the user is added in? Sounds like it may be the order in which the events occur. Right now, I am trying to find a way that I can keep track of the user being added to AD, before the commit happens. Please, post what you have and I'll be able to help you further.

 

Thanks

Aug 3, 2012 at 9:27 AM

http://cl.ly/0u0b2n3D1241

Here it is, my context with my entities, and the sample i ran.

Actually i add my user, after it i get it with a "Single(u => u.CN == "Firstname Lastname")" and i change his attributes with the method SetAttribute method, it work, but it's not very effective.

 

Thanks a lot.

Coordinator
Aug 3, 2012 at 7:36 PM
Edited Aug 3, 2012 at 7:36 PM

Lyrics,

I ran the program in my lab environment after changing the Attribute on the User class to [DirectoryType("User", "OU=ExternalUsers")] which is the OU where I can test and it worked fine for me.

After calling context.SubmitChanges() in your example, I re-queried the user:
single = context.Users.FirstOrDefault(u => u.CN == "Steve Baker"); 
And it returns to me this information:

CN = "Steve Baker"
DistinguishedName = "CN=Steve Baker,OU=ExternalUsers,DC=contoso,DC=com"
Email = "sbaker@test.com"
FirstName = "Steve"
Id = {b03f4f48-6170-455e-99db-88e1c7ed3a10}
LastName = "Baker"
UserName = "sbaker"

My guess would be to make sure your password matches the policy in place for your domain.

//HERE EXCEPTION : HRESULT : 0x80070544
single.SetPassword("Passw0rd");
//HERE EXCEPTION : HRESULT : 0x80070544

Let me know if this helps.

- Stephen 

Aug 3, 2012 at 8:18 PM

Steve,

I tested again my code, and i think i found why it doesn't work.
The SetPassword method doesn't work, so the program does not commit changes, and the user is not "activated" i guess. So that's why informations are not good.

But i have still the exception on the SetPassword method, and if i try to comment this line,  and commit the changes i got this error : "0000052D: SvcErr: DSID-031A120C, problem 5003 (WILL_NOT_PERFORM), data 0".

Maybe because it can't submit changes when nothing happened?

So you think my password not match the policy in place on my domain? But if i try to add a user with the UI, i can use this password and the user is activated.

Aug 3, 2012 at 9:17 PM

I found the problem, I tried to call my program accross a vpn, so if I launch an console app on the server, all is ok.

But I last question, have you any tips to add a group to a user ? I tried to change the memberof property but it's thrown an exception. Is their any method like SetPassword to do this? Thanks.

Coordinator
Aug 3, 2012 at 9:42 PM

After creating the user during testing, are you deleting the user and then running the test code again?

I researched the error you are getting and everything seems to say that the password doesn't meet the requirements of the policy, whether that be Length, complexity, or history. My suggestions are to 1) try modifying the password you are trying to set for the user to something more complex 2) try changing the user information to something else. Also, in order to set the CN of the user, you must use DirectoryEntry.Rename("CN=Your User").

Coordinator
Aug 3, 2012 at 11:08 PM
Edited Aug 3, 2012 at 11:10 PM

Unfortunately, there isn't any good way to do this through the linq to ad framework. I am trying to figure out a dynamic way to handle adding users to groups. Currently, you can only have the framework query a user's groups using the EntityCollection<T> property. That will not load the groups until the property is enumerated.

		[EntryCollectionProperty("member")]
		public EntryCollection<Group> Groups
		{
			get
			{
				return ((IEntryWithRelationships)this).RelationshipManager.GetEntryCollection<Group>("Groups");
			}
		}

Once, I have created a solution for this, I will document it and upload the updated source code to codeplex. But, until then, there isn't an easy way to handle that.

Aug 4, 2012 at 8:24 PM
Edited Aug 4, 2012 at 8:33 PM

I found a solution to add a user to a group. I have wroten my own GroupEntryObject class which inherited from EntryObject. After it i added a method in UserEntryObject which get the path of it, and you can use it like the third piece of code. Sorry for my english but it's not my native language. =)

public class GroupEntryObject : EntryObject
{
    public bool AddUser(string user)
    {
        if (string.IsNullOrEmpty(user))
            return false;

        var addUserResult = Entry.Invoke("Add", user);
        var result = addUserResult == null;

        if (!result)
            Marshal.ReleaseComObject(addUserResult);

        return result;
    }
}

public class UserEntryObject : EntryObject
{
    public string GetPath()
    {
        return this.Entry.Path;
    }
}

using (var context = new DirectoryContextMock())
{
    var singleUser = context.Users.Single(u => u.UserName == "Lyrics");
    var singleGrp = context.Groups.Single(u =>u.Name == "Main Project Developer");
    var result = singleGrp.AddUser(singleUser.GetPath());
}

Apr 9, 2014 at 9:06 AM
Hi,

Can you make the assemblies CLS-Compliant and sign them ?