This project has moved. For the latest updates, please go here.

WebClient in ImageDownloader/ImageProvisioningProvider doesn't get disposed

Apr 9, 2014 at 11:55 AM
Hi, I just stumbled over a non-disposed WebClient while profiling my application.

In ImageProvisioningProvider/ImageDownloader (your class names don't match your file names ;) ) there's this starting in line 99:
System.Net.WebClient webClient = new System.Net.WebClient();
if (proxy != null)
{
    if (proxy.Credentials != null)
        webClient.Credentials = proxy.Credentials;
    if (proxy.Proxy != null)
        webClient.Proxy = proxy.Proxy;
}

try
{
    imageInfo.RawData = webClient.DownloadData(imageUrl);

    // For requested url with no filename, we need to read the media mime type if provided
    imageInfo.Type = InspectMimeType(webClient);
}
catch (System.Net.WebException)
{
}
The first line should be:
using (var webClient = new WebClient())
Also seeing that empty catch block, it occurs to me that it'd be nice to have the possibility to inject a logger.

Thanks for your work on this nifty library! :)
Coordinator
Apr 10, 2014 at 11:11 AM
Hello,

I'm ashamed for the name of the class :)
But for the Dispose() of WebClient, I'm not agree with you:

WebClient inherits from Component and need a Dispose() if you attach it via the designer into a Windows Form for example.
But WebClient didn't override Dispose(bool disposed) and thus, no resources will be claimed.

About the empty catch, I already think about a logger. But I think people would want a more verbose logging (about the tag processed, style applied, ...) and the hard and long work it will generate to me.
So I drop the idea but after your post, yes I should implement one. I will read again the MSDN about TraceSource & TraceSwitch ....
Coordinator
Apr 18, 2014 at 11:44 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.