C # context is already tracking an object, azure active directory graph api. add group member

I am trying to add an item to the active azure directory group, but this does not allow me to show the following error.

context is already tracking an object

I tried to find a lot for this, I also see these links

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

http://blogs.msdn.com/b/aadgraphteam/archive/2014/12/12/announcing-azure-ad-graph-api-client-library-2-0.aspx

But I will not get any success, please help me.

This is my code:

try { ActiveDirectoryClient client = ADGraphHelper.GetActiveDirectoryClient(); IGroupFetcher groupFetcher = client.Groups.GetByObjectId(groupId); Group group = (Group)(await groupFetcher.ExecuteAsync()); string[] userIds = userId.Split(','); foreach (string id in userIds) { if (id != "") { IUser user = client.Users.Where(u => u.ObjectId == id).ExecuteAsync().Result.CurrentPage.ToArray().First(); if (user != null) { //check wather user aleady present into group or not IDirectoryObject userExists = group.Members.Where(u => u.ObjectId == id).FirstOrDefault(); if (userExists == null) { group.Members.Add(user as DirectoryObject); } } else throw new Exception("User is null."); } } await group.UpdateAsync(); return Json(new { success = true }); } catch (Exception ex) { ModelState.AddModelError("", "we connot process your request please contact to support for more details."); // error handling code. return PartialView(); } 
+1
source share
1 answer

Hello everyone, what I found in this question. it was a mistake from the old Graph client library. it is allowed in the Graph 2.0 client library, so use the graphical client library 2.0 or higher.

This is the link where you can download the latest graphical client library: https://www.nuget.org/packages/Microsoft.Azure.ActiveDirectory.GraphClient/

+1
source

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


All Articles