C# Microsoft graph api使用返回路径创建文件夹';无效请求';

C# Microsoft graph api使用返回路径创建文件夹';无效请求';,c#,api,microsoft-graph-api,onedrive,C#,Api,Microsoft Graph Api,Onedrive,graph api返回以下错误: "error": { "code": "invalidRequest", "message": "[child] A null value was found for the property named 'id', which has the expected type 'Edm.String[Nullable=False]'. The expected type 'Edm.String[Nullable=False]' does not allow nu

graph api返回以下错误:

  "error": {
"code": "invalidRequest",
"message": "[child] A null value was found for the property named 'id', which has the expected type 'Edm.String[Nullable=False]'. The expected type 'Edm.String[Nullable=False]' does not allow null values.",
"innerError": {
  "request-id": "36d65bbb-2f6e-485c-b2b9-5bb7fdb76d19",
  "date": "2017-09-30T00:24:06"
  }
}
我正在使用的代码:

var url = "https://graph.microsoft.com/v1.0/me/drive/root:/joba:/children";
var folder = new ItemResource { name = "nested", folder = new FolderFacet() };
var response = api.PostAsJsonAsync<ItemResource>(url, folder).Result;
response.ThrowWhenUnsuccessful();
return response.Content.ReadAsAsync<ItemResource>().Result;

PostAsJsonAsync
在封面下使用Json.NET,默认情况下,Json.NET将使用空值序列化属性。由于省略值不同于故意指定空值,当发生此值时,它触发OnDeReVAPI考虑请求无效,因为为非可空字段指定了空值。 要解决此问题,可以将以下属性添加到
ItemResource
类型上的可空属性中:

[JsonProperty(NullValueHandling=NullValueHandling.Ignore)]

或者,您可以使用Json.NET直接序列化对象,并提供一个适当配置的
JsonSerializerSettings
实例,然后调用
PostAsync

一看,您的请求看起来和预期的一样,我不会使用与您的代码非常相同的代码重新编写它。如果您可以捕获通过wire to Graph发送的请求和响应,并将其添加到您的问题中,这将有助于(不包括身份验证标记:)查看fiddler请求,我已经找到了答案。。我使用相同的模型来检索数据和发布数据,我在那里发布空的东西,graph不喜欢它
[JsonProperty(NullValueHandling=NullValueHandling.Ignore)]