.NET框架4.6.2流不支持并发io读取或编写操作

发布于 2025-01-19 01:11:16 字数 1714 浏览 3 评论 0原文

我的应用程序(在.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.taskFactory 1.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, Func5 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文