Azure Active Directory Graph Client 2.0 - Context does not currently track an object

I recently installed the Azure Active Directory Graph Client Library 2.0.2 Nuget package and cannot add members to groups by adding a group to a group or adding a user to a group. I get the following error when the AddLink function is called:

"[System.InvalidOperationException] = {" The context does not currently track the object. "}

My code is:

IGroup group = azureClient.Groups.GetByObjectId("Guid here").ExecuteAsync().Result; IGroup groupToAdd = azureClient.Groups.GetByObjectId("Guid here").ExecuteAsync().Result; azureClient.Context.AddLink(group, "Members", groupToAdd); azureClient.Context.SaveChanges(); 

I was unable to find a mention of this error regarding the Azure Active Directory graphical client library from performing a Google search, so any help on this would be appreciated.

+2
source share
3 answers

We just released an update for the Graph client library that fixes this problem. Now you can add members to groups. The mechanism is slightly different from using AddLinks (and hopefully easier).

We also have a new blog describing the client library that talks about this and much more: http://blogs.msdn.com/b/aadgraphteam/archive/2014/12/12/announcing-azure-ad-graph- api-client-library-2-0.aspx

For a link to add a member to a group:

{groupObject} .Members.Add ({entityObject} as DirectoryObject);

So, for example, to update a group with a new user:

myGroup.Members.Add (userToBeAdded as DirectoryObject); expect myGroup.UpdateAsync ();

NOTE. The same design can be used to add users to a DirectoryRole object. Groups and users can be added to the group, however at the moment only users can be added to the DirectoryRole.

Hope this helps,

+4
source

I had the same problem and the documentation was not very clear, so maybe this will help others. You cannot add users as members of IGroup , but only to Group . You also cannot add IDirectoryObject to the Members collection, but only DirectoryObject s. You must first draw the IUser and IGroup . The following code is what I'm working on now:

 var graphClient = new ActiveDirectoryClient(new Uri(ConfigHelper.GraphServiceRoot), async () => await GetUserTokenAsync(cache)); var actualUser = await graphClient.Users.GetByObjectId(matchedUser.ObjectId).ExecuteAsync(); var actualGroup = (Group) await graphClient.Groups.GetByObjectId(matchedGroup.ObjectId).ExecuteAsync(); actualGroup.Members.Add(actualUser as DirectoryObject); await graphClient.Context.SaveChangesAsync(); 
+2
source

I tried this new syntax but still not working.

  public async Task<Result<dynamic>> addUserToAzureGroup(Group AzGroup, User AzUser) { // link the found user with the found group try { AzGroup.Members.Add(AzUser as DirectoryObject); await AzGroup.UpdateAsync(); } catch (Exception ex) { Exception myEx = new Exception(ex.Message); retResult.Exception = myEx; return retResult; } return retResult; } 

I have almost the same error text in the progress message: Context is already tracking relationships

Any news on this? Can anyone guess why this is happening?

I also tried manage.windowsAzure.com from the user interface and still cannot add the user! I get this error: Failed to add members to the group 'myAzAD_group' .

0
source

Source: https://habr.com/ru/post/1210129/


All Articles