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