我正在尝试将成员添加到azure活动目录组,但它无法显示我跟随错误。
上下文已经在跟踪实体
我试图找到它很多,我也看到了这个链接
Azure Active Directory Graph Client 2.0 - Context is not currently tracking the entity
但是我没有取得任何成功,请帮助我。
这是我的代码:
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();
}
答案 0 :(得分:1)
嘿大家我发现现在的问题在于此。这是旧的Graph客户端库上的错误。它在Graph客户端库2.0中解决,因此请使用Graph客户端库2.0或更高版本。
这是您可以下载最新图形客户端库的链接: https://www.nuget.org/packages/Microsoft.Azure.ActiveDirectory.GraphClient/