You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Client bug]: Batch request retries, created with BatchRequestContentCollection.NewBatchWithFailedRequests, fail via GraphServiceClient.Batch.PostAsync due to a closed Stream
#2166
Describe the bug
Retrying request batches lead to an exception being thrown due to the inability to deserialize content from a closed Stream
To Reproduce
Steps to reproduce the behavior:
// build the batchvarbatchRequestContent=newBatchRequestContentCollection(graphClient);varrequestIds=newList<string>();// build a request for each list of attendees and add the request to the batchforeach(attendeeListinattendeesByRegion){varmeetingStartTime=newDateTimeTimeZone{DateTime=startTime,TimeZone=timeZone};varmeetingEndTime=newDateTimeTimeZone{DateTime=endTime,TimeZone=timeZone};GetSchedulePostRequestBodyrequestBody=newGetSchedulePostRequestBody(){AvailabilityViewInterval=timeInterval,EndTime=meetingEndTime,StartTime=meetingStartTime,Schedules=attendeeList,};varrequest=graphClient.Users[userEmailAddress].Calendar.GetSchedule.ToPostRequestInformation(requestBody, requestConfig =>requestConfig.Headers.Add("Prefer",$"outlook.timezone=\"{timeZone}\""));// add the request to the batchvarrequestId=awaitbatchRequestContent.AddBatchRequestStepAsync(request);requestIds.Add(requestId);};varbatchResponseContent=awaitgraphClient.Batch.PostAsync(batchRequestContent);varstatusCodes=awaitbatchResponseContent.GetResponsesStatusCodesAsync();varfailedRequests=statusCodes.Where(x =>!BatchResponseContent.IsSuccessStatusCode(x.Value));varsuccessfulRequests=statusCodes.Where(x =>BatchResponseContent.IsSuccessStatusCode(x.Value));// retry failed requestsvarfailedRequestDictionary=newDictionary<string,HttpStatusCode>();foreach(varrequestinrequests){failedRequestDictionary.Add(request.Key,request.Value);}varretryBatch=batchRequestContent.NewBatchWithFailedRequests(failedRequestDictionary);varbatchResponseContent=awaitgraphClient.Batch.PostAsync(retryBatch);
Expected behavior
For a BatchResponseContentCollection to be returned, containing the results of the retried requests
Screenshots
Exception thrown: 'Microsoft.Graph.ClientException' in System.Private.CoreLib.dll
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request.
Microsoft.Graph.ClientException: Unable to deserialize content.
---> System.ObjectDisposedException: Cannot access a closed Stream.
at System.IO.MemoryStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.MemoryStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)
--- End of stack trace from previous location ---
at System.Text.Json.JsonDocument.ReadToEndAsync(Stream stream, CancellationToken cancellationToken)
at System.Text.Json.JsonDocument.ParseAsyncCore(Stream utf8Json, JsonDocumentOptions options, CancellationToken cancellationToken)
at Microsoft.Graph.BatchRequestContent.GetRequestContentAsync(HttpRequestMessage request)
--- End of inner exception stack trace ---
at Microsoft.Graph.BatchRequestContent.GetRequestContentAsync(HttpRequestMessage request)
at Microsoft.Graph.BatchRequestContent.WriteBatchRequestStepAsync(BatchRequestStep batchRequestStep, Utf8JsonWriter writer)
at Microsoft.Graph.BatchRequestContent.GetBatchRequestContentAsync()
at Microsoft.Graph.Core.Requests.BatchRequestBuilder.ToPostRequestInformationAsync(BatchRequestContent batchRequestContent)
at Microsoft.Graph.Core.Requests.BatchRequestBuilder.PostAsync(BatchRequestContent batchRequestContent, CancellationToken cancellationToken, Dictionary`2 errorMappings)
at Microsoft.Graph.Core.Requests.BatchRequestBuilder.PostAsync(BatchRequestContentCollection batchRequestContentCollection, CancellationToken cancellationToken, Dictionary`2 errorMappings)
Client version
5.30.0
Desktop (please complete the following information):
OS: Windows 11
Browser: Chrome
Visual Studio Enterprise 2022 - 17.5.5
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
Describe the bug
Retrying request batches lead to an exception being thrown due to the inability to deserialize content from a closed Stream
To Reproduce
Steps to reproduce the behavior:
Expected behavior
For a BatchResponseContentCollection to be returned, containing the results of the retried requests
Screenshots
Client version
5.30.0
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: