I was having a code which was running perfectly to remove a user from an azure group but suddenly It stops working..when I debug the code Remove() method is returning false as a boolean. Below is the code which is not working.Can anyone please suggest me a quick fix.
public static async Task RemoveUserFromGroup(IGroup group, IUser user) {
RemoveFromGroupResult result = new RemoveFromGroupResult();
try
{
((Group)group).Members.Remove(user as DirectoryObject);
await group.UpdateAsync();
result.ErrorMsg = string.Empty;
}
catch (Exception e)
{
result.IsAdded = false;
result.ErrorMsg = e.Message;
}
return result;
According to my test, the code((Group)group).Member
always returns null List. So we cannot use the code ((Group)group).Members.Remove(user as DirectoryObject); await group.UpdateAsync();
to remove group member.
According to the situation, I suggest you use the Rest API to remove group member
DELETE https://graph.windows.net/myorganization/groups/{object_id}/$links/members/{member_id}?api-version=1.6