internal virtual void EndSend(IAsyncResult asyncResult) { if (asyncResult == null) { throw new ArgumentNullException(nameof(asyncResult)); } if (Content != null) { Content.EndSend(asyncResult); } else { LazyAsyncResult castedAsyncResult = asyncResult as LazyAsyncResult; if (castedAsyncResult == null || castedAsyncResult.AsyncObject != this) { throw new ArgumentException(Strings.net_io_invalidasyncresult); } if (castedAsyncResult.EndCalled) { throw new InvalidOperationException(string.Format(Strings.net_io_invalidendcall, nameof(EndSend))); } castedAsyncResult.InternalWaitForCompletion(); castedAsyncResult.EndCalled = true; if (castedAsyncResult.Result is Exception e) { ExceptionDispatchInfoThrower.Throw(e); } } }