We're using WebClient, .NET 3.5sp1 in a winforms application. For some users this results in an Exception with the message:
"The underlying connection was closed: A connection that was expected to be kept alive was closed by the server."
Searching a bit around the web suggests a "fix" to just disable http keepalive, which we're not really interested in doing, some suggests it might be a bug in the .NET libraries, etc.
The error message suggests it's a keepaliv'ed http connection that somehow got closed by the server(or a proxy) without the underlyings of WebClient detecting it properly.
We're thinking of catching this specific case, and simply try the request again. However we cannot reproduce this exception. So.
How can we properly catch the case that yields the above error message.
catch(WebException ex) { if (ex.Message == "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server") { ... }
smells.. bad.
Any tips on how we can reproduce the above exception ?
WebClient detects this just fine. Thus the exception. You need to find the server that's misbehaving. Not quite sure what to do if you find that server, maybe you can send the admin a nice email message.
Log the server URL.
I suggest you have a look at this blog by Misrosoft: Http Client Protocol Issues
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With