MS Graph SDK: задачи планировщика: элемент с таким же ключом уже добавлен - PullRequest
0 голосов
/ 03 февраля 2020

Я использую следующий код для создания задачи под планировщиком с помощью MS Graph SDK. Для задачи 1 она работает должным образом, но при добавлении второй задачи возникает ошибка.

 foreach (var bucket in buckets)
                {
                    foreach (var task in bucket.Tasks)
                    {
                        task.PlanId = plan.Id;
                        task.BucketId = bucket.Id;
                        task.StartDateTime = DateTime.UtcNow;
                        task.DueDateTime = DateTime.UtcNow.AddDays(10);
                        var createdTask = await graphServiceClient.Planner.Tasks.Request().AddAsync(
                            new Microsoft.Graph.PlannerTask
                            {
                                DueDateTime = DateTime.UtcNow.AddDays(10),
                                Title = task.Title,
                                Assignments = assignments,
                                PlanId = plan.Id,
                                BucketId = bucket.Id,
                            }
                        );
                        var createdTasddk = await graphServiceClient.Planner.Plans[plan.Id].Tasks.Request().GetAsync();

                    }
                }

Ошибка:

 {System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: An item with the same key has already been added. Key: @odata.type
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Newtonsoft.Json.Serialization.JsonContract.<>c__DisplayClass57_0.<CreateSerializationCallback>b__0(Object o, StreamingContext context)
   at Newtonsoft.Json.Serialization.JsonContract.InvokeOnSerializing(Object o, StreamingContext context)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.OnSerializing(JsonWriter writer, JsonContract contract, Object value)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
   at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Microsoft.Graph.BaseRequest.SendAsync[T](Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at S27.Application.Services.MSGraphAPIService.CreateTask(PlannerPlan plan, IList`1 buckets, IList`1 members, GraphServiceClient graphServiceClient)}

Что здесь не так. Как я могу это исправить?

Спасибо.

...