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(); }
source share