Although topic has been discussed here before, but the proposed solutions don't seem to work..
I have a button-click-callback method in my form application, that shows a folder picker 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 produces 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 calling dialog.Dispose without any blocks, all to no avail - the warning remains, always at the line of initialization.