Reputation: 21244
I'm using StreamWriter to pass a large amount of data (30mb+) via a WebRequest POST. It fails with the error The stream does not support concurrent IO read or write operations. Contrary to the error message, I am not performing concurrent operations -- the app is single threaded and the StreamWriter logic is very straightforward.
string data = "......."; // 30mb+ of text
var webRequest = WebRequest.Create(someUrl);
webRequest.Method = "POST";
webRequest.ContentLength = data.Length;
using (var writer = new StreamWriter(webRequest.GetRequestStream()))
writer.Write(data);
I suspect the large amount of data is to blame. I've seen references to this error from Team Foundation System users who get this error when uploading large files ([1], [2]), however I haven't seen large data being discussed as the cause outside of TFS discussions.
Am I truly running into some limit with StreamWriter? Is there are more efficient way to stream this data?
Upvotes: 1
Views: 594
Reputation: 21244
The root problem was my POST request was so large that I had exceeded the target server's maxAllowedContentLength setting. The fix was to increase the value of this setting.
I'm not sure why I got a "concurrent IO" error but it only happened when I set webRequest.ContentLength
. When I commented that line out I was able to see the WebRequest received a 404 from the server. This eventually led me to discover the issue with maxAllowedContentLength.
Upvotes: 1