BatchRequestContentCollection.NewBatchWithFailedRequests failes because BatchRequestSteps is not correct.
Marcelvl opened this issue · 0 comments
Please provide the following (and please check them off the list with [x]) before submitting this issue:
- Expected behavior. Please provide links to the specific Microsoft Graph documentation you used to determine the expected behavior.
- Actual behavior. Provide error codes, stack information, and a Fiddler capture of the request and response (please remove personally identifiable information before posting).
- Steps to reproduce the behavior. Include your code, IDE versions, client library versions, and any other information that might be helpful to understand your scenario.
Expected behavior
Call to BatchRequestContentCollection.NewBatchWithFailedRequests should also succeed when the BatchRequestContentCollection instance contains more than 20 requests.
Actual behavior
Call to BatchRequestContentCollection.NewBatchWithFailedRequests on a BatchRequestContentCollection instance containing more than 20 requests throws an exception.
Callstack
at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException[T](T key)
at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary
2.Add(TKey key, TValue value)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func
2 keySelector, Func2 elementSelector, IEqualityComparer
1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func
2 keySelector, Func2 elementSelector) at Microsoft.Graph.BatchRequestContentCollection.get_BatchRequestSteps() at Microsoft.Graph.BatchRequestContentCollection.NewBatchWithFailedRequests(Dictionary
2 responseStatusCodes)
Steps to reproduce the behavior
//Create a BatchRequestContentCollection instance.
var batchRequestContent = new BatchRequestContentCollection(graphClient);
//Add more than 20 steps to this instance.
for (int i = 0; i < messagesToDelete.Count; i++)
{
var requestInformation = graphClient.Users[user].MailFolders[mailFolder].Messages[messagesToDelete[i]].ToDeleteRequestInformation();
await batchRequestContent.AddBatchRequestStepAsync(requestInformation).ConfigureAwait(false);
}
//Post this batch instance to graph.
var batchResponseContent = await graphClient.Batch.PostAsync(batchRequestContent).ConfigureAwait(false);
//Get status codes from batch-call
var statusCodes = await batchResponseContent.GetResponsesStatusCodesAsync().ConfigureAwait(false);
//retry the failed calls. This results in the exception
var retryBatch = batchRequestContent.NewBatchWithFailedRequests(statusCodes);
//NewBatchWithFailedRequests calls BatchRequestSteps. BatchRequestSteps adds currentRequest.BatchRequestSteps twice because it is also present in "batchRequests"