.NET框架4.6.2流不支持并发io读取或编写操作
我的应用程序(在.NET Framework 4.6.2上运行)将文件作为流将文件上传到我自己的API(.NET 6),有时我会在应用程序上得到一个例外:
system.notsupportedException:该流不支持并发io读取或编写操作。
在system.net.connectstream.internalwrite(boolean async,byte [] buffer,int32 offset,int32 size,asynccallback回调,对象状态)
在system.net.connectstream.beginwrite(byte [] buffer,int32 offset,int32 size,asynccallback回调,对象状态)) 在System.IO.Stream。 at System.Threading.tasks.taskFactory1.Fromasynctrim [Tinstance,Targs](Tinstance thisRef,Targs args,func
5 beginmethod,func`3 endMethod) 在System.IO.Stream.BeginendWriteAsync(字节[] buffer,INT32偏移,INT32计数)上 在System.IO.Stream.WriteAsync(字节[]缓冲区,INT32偏移,INT32计数,cancellationToken concellationToken) 在System.IO.Stream.d__27.movenext() ---堆栈跟踪的结尾是从上面抛出例外的位置------ at System.Runtime.compilerServices.taskawaiter.throwfornonsuccess(任务任务) 在system.runtime.com.pilerservices.taskawaiter.handlenonsuccessanddebuggernotification(任务任务) 在system.net.http.httpcontent.d__44.movenext() ---堆栈跟踪的结尾是从上面抛出例外的位置------ at System.Runtime.compilerServices.taskawaiter.throwfornonsuccess(任务任务) 在system.runtime.com.pilerservices.taskawaiter.handlenonsuccessanddebuggernotification(任务任务) 在System.net.http.httpclient.d__58.movenext()
该流在API中没有接触到它刚刚传输到存储(使用SDK的存储帐户)。
客户端没有任何变化,它只是在服务器端更改。客户端应用程序没有并行化。该文件的读取没有共享选项,并将上传到云API端点。
API从.NET框架4.6.2到.NET
。
var stream = await Request.Content.ReadAsStreamAsync().ConfigureAwait(true);
更改:
var stream = Request.Body;
6 溪流。
是否有人遇到相同的问题或想法我的代码中可能是什么问题?
已经找到了这样的帖子流不支持并发io io io读取或编写操作
My application (running on .NET Framework 4.6.2) uploads an file as stream to my own api (.NET 6) and sometimes I get an exception on the application about:
System.NotSupportedException: The stream does not support concurrent IO read or write operations.
at System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.IO.Stream.<>c.b__53_0(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state)
at System.Threading.Tasks.TaskFactory1.FromAsyncTrim[TInstance,TArgs](TInstance thisRef, TArgs args, Func
5 beginMethod, Func`3 endMethod)
at System.IO.Stream.BeginEndWriteAsync(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at System.IO.Stream.d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpContent.d__44.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpClient.d__58.MoveNext()
The stream is not touched in the api it is just transferred to a storage (storage account by using the sdk).
Nothing change on the client side it just changed on server side. There is no parallelization on the client app. The file is read with no shared options and is uploaded to the cloud api endpoint.
Change: the api was migrated from .NET Framework 4.6.2 to .NET 6.
At the controller there change the read stream line from:
var stream = await Request.Content.ReadAsStreamAsync().ConfigureAwait(true);
to
var stream = Request.Body;
It feels like .NET Core has changed the behavior of read the stream.
Is there someone which had the same issue or an idea what could be the issue in my code?
Already found posts like this The stream does not support concurrent IO read or write operations
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论