CA2000: object not located on all exception paths

Although the topic has been discussed here before, the proposed solutions do not seem to work.

I have a click-click-callback method in my form application that displays a folder selection dialog:

private void ButtonSelectReporterFolderClick(object sender, EventArgs e) { using (var dialog = new FolderBrowserDialog()) // causes warning { if (dialog.ShowDialog() == DialogResult.OK) { this.boxReporterFolderPath.Text = dialog.SelectedPath; } } } 

This raises a warning:

CA2000: Microsoft.Reliability : In method 'MainWindow.ButtonSelectReporterFolderClick(object, EventArgs)', object '<>g__initLocal' is not disposed along all exception paths. Call System.IDisposable.Dispose on object '<>g__initLocal' before all references to it are out of scope.

I also tried using a try - finally block or even a call. Do not use any blocks, all to no avail - the warning always remains in the initialization line.

+7
source share
1 answer

The warning is not related to the fact that the FolderBrowserDialog is not configured, because it has some public elements that implement the IDisposable interface and you do not delete them separately. Of course, the FolderBrowserDialog object knows how to get rid of its dependencies, but FxCop does not know that this gives a warning. Just ignore the warning in your case.

+5
source

All Articles