0

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Changer
  • 85
  • 1
  • 7
  • I do not think the connection is completing. – jdweng Apr 05 '22 at 13:40
  • Looks like it is related to this issue: https://developercommunity.visualstudio.com/t/experiencing-notsupportedexception-when-using-http/1195371 If this would be the case, it will just fixed in case the client framework is replaced – Changer Apr 12 '22 at 12:36
  • If you have client and server in same application then you are making a virtual connection. The client socket (sending the request) and server socket (receiving the request) should be completely independent. To get a concurrent read and write error means you are trying in the server code to read the client socket. instead of the server socket. It may not give an error every time since the client may send all the data before the server attempts to read. But there may be cases where the client doesn't finish sending before the server starts to read. – jdweng Apr 12 '22 at 13:40

0 Answers0