Closed Ivony closed 5 years ago
谢谢你的反馈,这段代码你可以先按照如下方式修改: _stream = = new MemoryStream(); _response.Content.CopyToAsync(_stream).Wait(); ==> var tmpStream = new MemoryStream(); _stream.CopyToAsync(tmpStream).Wait(); _stream = tmpStream;
已更新到master 分支
https://github.com/aliyun/aliyun-oss-csharp-sdk/blob/d0126ce699b93004ffee6a732c38dbfd24a7f55b/sdk/Common/Communication/netcore/ServiceClientNewImpl.cs#L68
原因也非常简单,你们上面已经读取过一次Content Stream了,发现状态码不是200 OK的时候又读取一次Content Stream,就会造成这个异常:
System.AggregateException: One or more errors occurred. (The stream was already consumed. It cannot be read again.) ---> System.InvalidOperationException: The stream was already consumed. It cannot be read again. at System.Net.Http.HttpConnection.HttpConnectionResponseContent.ConsumeStream() at System.Net.Http.HttpConnection.HttpConnectionResponseContent.SerializeToStreamAsync(Stream stream, TransportContext context, CancellationToken cancellationToken) at System.Net.Http.HttpContent.CopyToAsyncCore(ValueTask copyTask) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at Aliyun.OSS.Common.Communication.ServiceClientNewImpl.ResponseImpl..ctor(HttpResponseMessage httpWebResponse) at Aliyun.OSS.Common.Communication.ServiceClientNewImpl.SendCore(ServiceRequest request, ExecutionContext context) at Aliyun.OSS.Common.Communication.ServiceClient.Send(ServiceRequest request, ExecutionContext context) at Aliyun.OSS.Common.Communication.RetryableServiceClient.SendImpl(ServiceRequest request, ExecutionContext context, Int32 retryTimes) at Aliyun.OSS.Commands.OssCommand.Execute() at Aliyun.OSS.OssClient.ListObjects(ListObjectsRequest listObjectsRequest) ……