I am using HttpClient and PushStreamContent to upload 1GB of data. I noticed that if I do _not_ use the try-catch below, I am not seeing any exception thrown. Actually there is an out-of-memory exception being thrown by HttpClient here. Re-enable the commented try-catch block and you should see the problem.
__Attached__ a standalone repro.
```
// 1. PushStreamContent (this is not seekable)
request.Content = new PushStreamContent((requestStream, content, transportContext) =>
{
//try
//{
using (requestStream)
{
for (long i = 0; i < iterations; i++)
{
// writing chunks of 1KB to the wire
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Flush();
}
if (remainingBytes > 0)
{
requestStream.Write(buffer, 0, (int)remainingBytes);
requestStream.Flush();
}
}
//}
//catch (Exception ex) //NOTE: without this try-catch block, i do not see any error thrown
//{
// Console.WriteLine("Exception occurred while writing to request stream:\n{0}\n", ex.ToString());
//}
});
```
__Attached__ a standalone repro.
```
// 1. PushStreamContent (this is not seekable)
request.Content = new PushStreamContent((requestStream, content, transportContext) =>
{
//try
//{
using (requestStream)
{
for (long i = 0; i < iterations; i++)
{
// writing chunks of 1KB to the wire
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Flush();
}
if (remainingBytes > 0)
{
requestStream.Write(buffer, 0, (int)remainingBytes);
requestStream.Flush();
}
}
//}
//catch (Exception ex) //NOTE: without this try-catch block, i do not see any error thrown
//{
// Console.WriteLine("Exception occurred while writing to request stream:\n{0}\n", ex.ToString());
//}
});
```