Skip to content

Commit

Permalink
[Azure Search] Prevent ObjectDisposedException when Indexing using "M…
Browse files Browse the repository at this point in the history
…erge" operation (Azure#7011)

* Fix the request content being disposed betweeen .NET Core and .Net framework

* Add SessionRecord for the new test
  • Loading branch information
arv100kri authored and weshaggard committed Jul 24, 2019
1 parent 39b91f4 commit 4839ca2
Show file tree
Hide file tree
Showing 3 changed files with 598 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,15 @@ await Client.DocumentsProxy.IndexWithHttpMessagesAsync(
HttpRequestMessage httpRequest = result.Request;
HttpResponseMessage httpResponse = result.Response;

// NOTE: It is not possible to read the http request's string content property here,
// via .NET framework's HttpClient, as the Content gets disposed as soon as the request is sent.
// Thus the batch is re-serialized, which is what happens in the IndexWithHttpMessagesAsync() method
// In .NET Core, the Content doesn't get disposed, so it's safe to read the string content here.
#if FullNetFx
string requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(batch, jsonSettings);
#else
string requestContent = await httpRequest.Content.ReadAsStringAsync().ConfigureAwait(false);
#endif
string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

var exception =
Expand Down
Loading

0 comments on commit 4839ca2

Please sign in to comment.