protected void AsyncEndGetRequestStream(IAsyncResult asyncResult) { AsyncStateBag asyncState = asyncResult.AsyncState as AsyncStateBag; PerRequest request = (asyncState == null) ? null : asyncState.PerRequest; DataServiceContext context = (asyncState == null) ? null : asyncState.Context; try { this.CompleteCheck(request, InternalError.InvalidEndGetRequestCompleted); request.SetRequestCompletedSynchronously(asyncResult.CompletedSynchronously); EqualRefCheck(this.perRequest, request, InternalError.InvalidEndGetRequestStream); Stream stream = Util.NullCheck <Stream>(WebUtil.EndGetRequestStream(Util.NullCheck <ODataRequestMessageWrapper>(request.Request, InternalError.InvalidEndGetRequestStreamRequest), asyncResult, context), InternalError.InvalidEndGetRequestStreamStream); request.RequestStream = stream; ContentStream requestContentStream = request.RequestContentStream; Util.NullCheck <ContentStream>(requestContentStream, InternalError.InvalidEndGetRequestStreamContent); Util.NullCheck <Stream>(requestContentStream.Stream, InternalError.InvalidEndGetRequestStreamContent); if (requestContentStream.IsKnownMemoryStream) { MemoryStream stream3 = requestContentStream.Stream as MemoryStream; byte[] buffer = stream3.GetBuffer(); int position = (int)stream3.Position; int num2 = ((int)stream3.Length) - position; if ((buffer == null) || (num2 == 0)) { Error.ThrowInternalError(InternalError.InvalidEndGetRequestStreamContentLength); } } request.RequestContentBufferValidLength = -1; Stream stream1 = requestContentStream.Stream; asyncResult = InvokeAsync(new AsyncAction(stream1.BeginRead), request.RequestContentBuffer, 0, request.RequestContentBuffer.Length, new AsyncCallback(this.AsyncRequestContentEndRead), asyncState); request.SetRequestCompletedSynchronously(asyncResult.CompletedSynchronously); } catch (Exception exception) { if (this.HandleFailure(request, exception)) { throw; } } finally { this.HandleCompleted(request); } }