Annoying C# Web Exception …


The request was aborted: The request was canceled.

Cannot close stream until all bytes are written.

If you’re getting that exception, make sure that the timeout for the webrequest is set sufficiently to handle the request. The default as of .NET 3.5 SP1 seems to be 100 seconds. I’m working on an fix to SnugUp and discovered that large files would throw the exception above. I thought it must be a problem on the SmugMug side, but couldn’t come up with a rational reason why it would just fail with my application … and then it dawned on me that it was closing the stream early because it had exceeded the timeout!

So, if you’ve seen that exception, and can’t figure it out … consider checking the timeout. (Also, verify the content-length is set properly – that’s another reason this exception might be thrown).