I have an object that is declared at the class level which is giving CA2000 warning. How can I get rid of the CA2000 warning from the code below?
public partial class someclass : Window
{
System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog()
{
AddExtension = true,
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = "xsd",
FileName = lastFileName,
Filter = "XML Schema Definitions (*.xsd)|*.xsd|All Files (*.*)|*.*",
InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop),
RestoreDirectory = true,
Title = "Open an XML Schema Definition File"
};
}
The warning is- Warning CA2000 In method 'SIMPathFinder.SIMPathFinder()', object 'new OpenFileDialog()' is not disposed along all exception paths. Call System.IDisposable.Dispose on object 'new OpenFileDialog()' before all references to it are out of scope.