System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly

If you are using .NET 2.0 or above can you enable network tracing and see what's actually happening over the wire. In that way you can get more information about this particular exception.

See following link for more details, http://msdn.microsoft.com/en-us/library/hyb3xww8%28VS.80%29.aspx


In my case, this solved the problem:

System.Net.ServicePointManager.Expect100Continue = false;

and none of the above.


I encountered the same exception a while ago and I remember that this happens in some cases due to a bug in .NET. You can work around this by setting the Timeout and ReadWriteTimeout of the request to higher values, or set KeepAlive to false.

This would only be a workaround, though, so I suggest you try to find the actual root cause before assuming anything.

I'll try to come up with some web references, in the mean time, look at Big files uploading (WebException: The connection was closed unexpectedly)

Tags:

C#

Asp.Net