My WPF application consists of a main window, which in turn has a child window.
If I let the child window open a FolderBrowserDialog, I get a System.ComponentModel.Win32Exception (A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in WindowsBase.dll). More specifically this occurs after closing the dialog, and when the child window gets focus again (?). The question mark is there because I haven't succeeded in catching the exception so I'm not 100% sure. But visually, that is when it occurs. If the child window has focus after closing the dialog, the exception occurs after the window looses focus and the regains it.
If I move the code opening the folderBrowserDialog to the main window, this does not happen. ***EDIT: Now it also crashes the program from the main window too.
Why do I get this exception? What is happening? How can I fix it (apart from moving it to the main window)?
Here is the code opening the dialog; nothing extraordinary. Exception code removed.
FolderBrowserDialog dlg = new FolderBrowserDialog();
DialogResult result = dlg.ShowDialog();
if (result == DialogResult.OK)
selDir = dlg.SelectedPath;
I'm using VS2010, .Net 4.