Normally, one writes code something like this to download some data using a WebRequest.
using(WebResponse resp = request.GetResponse()) // WebRequest reques
using (var x = GetObject()) {
statements;
}
is (almost) equivalent to
var x = GetObject();
try {
statements;
}
finally {
((IDisposable)x).Dispose();
}
so your object will always be disposed.
This means that in your case
try {
using (WebResponse resp = request.GetResponse()) {
something;
}
}
catch (WebException ex) {
DoSomething(ex.Response);
}
ex.Response will be the same object as your local resp object, which is disposed when you get to the catch handler. This means that DoSomething is using a disposed object, and will likely fail with an ObjectDisposedException.