Okay, I'm afraid I'm a bit lost on this one. The following code gives a CA 2000 warning that "'new WebRequestHandler()' is not disposed along all exception paths".
this.webHandler = new WebRequestHandler()
{
AllowAutoRedirect = true,
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache),
CookieContainer = cookies,
ReadWriteTimeout = 5000
};
I struggled with that for a good 20 minutes before discovering that what I'm convinced is functionally the same code does not give that same warning.
this.webHandler = new WebRequestHandler();
this.webHandler.AllowAutoRedirect = true;
this.webHandler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
this.webHandler.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
this.webHandler.CookieContainer = cookies;
this.webHandler.ReadWriteTimeout = 5000;
Obviously, the solution is to use the latter approach (or just suppress the warning), but is there something wrong with the first approach that I'm just not aware of?