无法在 'Team' 类型的对象上找到成员“@odata.type”
Could not find member '@odata.type' on object of type 'Team'
我在将团队添加到以前使用 Microsoft Graph 创建的组时遇到问题。
我正在使用 Microsoft Graph .NET Client Library (1.19.0) to work with Microsoft Graph, following the .NET Core tutorial here。
身份验证是通过客户端流程进行的(控制台 运行 作为守护进程),我在构建 graphClient
或身份验证时没有遇到任何问题:
// Auth info
var tenantId = "xxx";
var clientId = "xxx";
var clientSecret = "xxx";
var scopes = new List<string> { "https://graph.microsoft.com/.default" };
// Create ConfidentialClientApplication
var confidentialClientApplication = ConfidentialClientApplicationBuilder.Create(clientId)
.WithAuthority(AzureCloudInstance.AzurePublic, tenantId)
.WithClientSecret(clientSecret)
.Build();
// Create authenticationProvider
ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication, scopes[0]);
// Create graph client
// Use graph BETA endpoint
var baseUrl = "https://graph.microsoft.com/beta/";
var graphServiceClient = new GraphServiceClient(baseUrl, authenticationProvider);
或创建群组:
var groupName = "Team group";
var groupDescription = "Awesome group";
var group = new Group
{
DisplayName = groupName,
Description = groupDescription,
GroupTypes = new List<string> { "Unified" },
Visibility = "Private",
MailNickname = groupName.Replace("", string.Empty).ToLower(),
MailEnabled = false,
SecurityEnabled = false
};
// Send the POST request to create group
group = await graphServiceClient.Groups.Request().AddAsync(group);
但是在将团队添加到新组时:
var team = new Team();
await graphServiceClient
.Groups[group.Id]
.Team
.Request()
.PutAsync(team);
我收到以下错误:
Code: InvalidRequest
Message: Could not find member '@odata.type' on object of type 'Team'. Path '['@odata.type']', line 1, position 15.
Inner error:
AdditionalData:
request-id: xxx
date: 2019-10-30 09:12:04
ClientRequestId: xxx
但是当将团队模型序列化为 JSON 时,结果是:
{"@odata.type":"microsoft.graph.team"}
这表明有一个 OData 成员具有一种类型的团队。
我尝试按照此处的建议添加 NuGet 包 Microsoft.AspNet.OData
和 Microsoft.Data.OData
:Could not find member '@odata.type' on object of type 'TeamMemberSettings',但没有成功。
我也试过直接用 HttpRequest
调用端点,结果相同。我还尝试在 .NET Core 和 .Net Framework 应用程序中使用相同的代码。
虽然您可以重新指向 Microsoft Graph SDK to the Beta version, it will still only use the v1.0 data models. To actually use the Microsoft Graph Beta, you should use the Microsoft Graph Beta SDK。
Install-Package Microsoft.Graph.Beta -Version 0.8.0-preview
您还使用了一个已弃用的端点,该端点将在年底前删除。来自 documentation:
This API is in the process of being deprecated in favor of Create team, and will be removed by the end of 2019. For details about how to create a team from a group, see examples 4 and 5 in Create team.
要创建 Team from a Group,您可以像这样发出 POST
:
await graphServiceClient
.Groups[group.Id]
.Team
.Request()
.PostAsync(team);
此外,请记住来自 documentation 的注释:
If the group was created less than 15 minutes ago, it's possible for the Create team call to fail with a 404 error code due to replication delays. We recommend that you retry the Create team call three times, with a 10 second delay between calls.
我在将团队添加到以前使用 Microsoft Graph 创建的组时遇到问题。
我正在使用 Microsoft Graph .NET Client Library (1.19.0) to work with Microsoft Graph, following the .NET Core tutorial here。
身份验证是通过客户端流程进行的(控制台 运行 作为守护进程),我在构建 graphClient
或身份验证时没有遇到任何问题:
// Auth info
var tenantId = "xxx";
var clientId = "xxx";
var clientSecret = "xxx";
var scopes = new List<string> { "https://graph.microsoft.com/.default" };
// Create ConfidentialClientApplication
var confidentialClientApplication = ConfidentialClientApplicationBuilder.Create(clientId)
.WithAuthority(AzureCloudInstance.AzurePublic, tenantId)
.WithClientSecret(clientSecret)
.Build();
// Create authenticationProvider
ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication, scopes[0]);
// Create graph client
// Use graph BETA endpoint
var baseUrl = "https://graph.microsoft.com/beta/";
var graphServiceClient = new GraphServiceClient(baseUrl, authenticationProvider);
或创建群组:
var groupName = "Team group";
var groupDescription = "Awesome group";
var group = new Group
{
DisplayName = groupName,
Description = groupDescription,
GroupTypes = new List<string> { "Unified" },
Visibility = "Private",
MailNickname = groupName.Replace("", string.Empty).ToLower(),
MailEnabled = false,
SecurityEnabled = false
};
// Send the POST request to create group
group = await graphServiceClient.Groups.Request().AddAsync(group);
但是在将团队添加到新组时:
var team = new Team();
await graphServiceClient
.Groups[group.Id]
.Team
.Request()
.PutAsync(team);
我收到以下错误:
Code: InvalidRequest
Message: Could not find member '@odata.type' on object of type 'Team'. Path '['@odata.type']', line 1, position 15.
Inner error:
AdditionalData:
request-id: xxx
date: 2019-10-30 09:12:04
ClientRequestId: xxx
但是当将团队模型序列化为 JSON 时,结果是:
{"@odata.type":"microsoft.graph.team"}
这表明有一个 OData 成员具有一种类型的团队。
我尝试按照此处的建议添加 NuGet 包 Microsoft.AspNet.OData
和 Microsoft.Data.OData
:Could not find member '@odata.type' on object of type 'TeamMemberSettings',但没有成功。
我也试过直接用 HttpRequest
调用端点,结果相同。我还尝试在 .NET Core 和 .Net Framework 应用程序中使用相同的代码。
虽然您可以重新指向 Microsoft Graph SDK to the Beta version, it will still only use the v1.0 data models. To actually use the Microsoft Graph Beta, you should use the Microsoft Graph Beta SDK。
Install-Package Microsoft.Graph.Beta -Version 0.8.0-preview
您还使用了一个已弃用的端点,该端点将在年底前删除。来自 documentation:
This API is in the process of being deprecated in favor of Create team, and will be removed by the end of 2019. For details about how to create a team from a group, see examples 4 and 5 in Create team.
要创建 Team from a Group,您可以像这样发出 POST
:
await graphServiceClient
.Groups[group.Id]
.Team
.Request()
.PostAsync(team);
此外,请记住来自 documentation 的注释:
If the group was created less than 15 minutes ago, it's possible for the Create team call to fail with a 404 error code due to replication delays. We recommend that you retry the Create team call three times, with a 10 second delay between calls.