C# 使用Graph API向azure active directory中的组添加成员时出现URl无效错误

C# 使用Graph API向azure active directory中的组添加成员时出现URl无效错误,c#,asp.net,asp.net-core,azure-active-directory,azure-ad-graph-api,C#,Asp.net,Asp.net Core,Azure Active Directory,Azure Ad Graph Api,我正在尝试使用C#中的Graph API向Azure Active directory中的组添加成员,但当我运行代码时,出现以下错误: ServiceException:代码:BadRequest 消息:无效的URL格式 在@odata.bind中为成员指定 下面是我的代码: [AuthorizeForScopes(Scopes = new[] { Constants.GroupMemberReadWriteAll, Constants.DirectoryReadAsUser })] publi

我正在尝试使用C#中的Graph API向Azure Active directory中的组添加成员,但当我运行代码时,出现以下错误:

ServiceException:代码:BadRequest
消息:无效的URL格式 在@odata.bind中为成员指定

下面是我的代码:

[AuthorizeForScopes(Scopes = new[] { Constants.GroupMemberReadWriteAll, Constants.DirectoryReadAsUser })]
public async Task<IActionResult> AddMembersToGroup()
{
    MSGraphs.GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.GroupMemberReadWriteAll, Constants.DirectoryReadAsUser });

            var group = new MSGraphs.Group
            {
                AdditionalData = new Dictionary<string, object>()
                {
                    {"members@odata.bind", "[\"https://graph.microsoft.com/v1.0/directoryObjects/c6e5c868-e2bd-46b0-b5f3-c39b5dfe42dc\",\"https://graph.microsoft.com/v1.0/directoryObjects/b2fc878b-a455-4315-b9e1-8594cbad3404\",\"https://graph.microsoft.com/v1.0/directoryObjects/79f06743-3bee-418e-8f4e-b381ebdfafc2\"]"}
                }
            };

            await graphClient.Groups["{29f7e645-8de1-45fc-80a5-e76e0fa51340}"]
                .Request()
                .UpdateAsync(group);

            return Ok();
        }
[AuthorizeForScopes(Scopes=new[]{Constants.GroupMemberReadWriteAll,Constants.DirectoryReadAsUser}]
公共异步任务AddMembersToGroup()
{
MSGraphs.GraphServiceClient graphClient=GetGraphServiceClient(新[]{Constants.GroupMemberReadWriteAll,Constants.DirectoryReadAsUser});
var group=新的MSGraphs.group
{
AdditionalData=新字典()
{
{"members@odata.bind", "[\"https://graph.microsoft.com/v1.0/directoryObjects/c6e5c868-e2bd-46b0-b5f3-c39b5dfe42dc\",\"https://graph.microsoft.com/v1.0/directoryObjects/b2fc878b-a455-4315-b9e1-8594cbad3404\",\"https://graph.microsoft.com/v1.0/directoryObjects/79f06743-3bee-418e-8f4e-b381ebdfafc2\"]"}
}
};
等待图形客户端组[“{29f7e645-8de1-45fc-80a5-e76e0fa51340}]
.Request()
.UpdateAsync(集团);
返回Ok();
}

如果我在这里遗漏了什么,请告诉我。

您可以使用字符串数组,而不是将成员作为字符串提供(通过预期JSON序列化):

var group = new MSGraphs.Group
  {
    AdditionalData = new Dictionary<string, object>()
      {
         { 
            "members@odata.bind", 
            new string[] 
            { 
              "https://graph.microsoft.com/v1.0/directoryObjects/c6e5c868-e2bd-46b0-b5f3-c39b5dfe42dc",
              "https://graph.microsoft.com/v1.0/directoryObjects/b2fc878b-a455-4315-b9e1-8594cbad3404",
              "https://graph.microsoft.com/v1.0/directoryObjects/79f06743-3bee-418e-8f4e-b381ebdfafc2" 
            }
         }
     }
  };
var group=new MSGraphs.group
{
AdditionalData=新字典()
{
{ 
"members@odata.bind", 
新字符串[]
{ 
"https://graph.microsoft.com/v1.0/directoryObjects/c6e5c868-e2bd-46b0-b5f3-c39b5dfe42dc",
"https://graph.microsoft.com/v1.0/directoryObjects/b2fc878b-a455-4315-b9e1-8594cbad3404",
"https://graph.microsoft.com/v1.0/directoryObjects/79f06743-3bee-418e-8f4e-b381ebdfafc2" 
}
}
}
};
这样,.NET就可以在以后处理序列化