So I'm using the CommonOpenFileDialog from the windowsAPICodepack. In a previous version of the application I'm writing, the CommonOpenFileDialog worked without any problems. In the current version targeted at a higher version of the .Net Framework, I get Cross-thread operation not valid exceptions even though the dialog is called from the main UI thread trough a toolstripMenuItem click event from the main form. Before it used to be called in a similar way from a button clickhandler of the main form.
Explicitly Invoking the same code that shows the CommonOpenFileDialog on the same form solves this, but the usual dialog behavior gets lost this way.
This works, but without the this.Invoke it does not.
   private void loadWorkspaceToolStripMenuItem_Click(object sender, EventArgs e)
    {
        bool wait = true;
        this.Invoke((MethodInvoker)delegate ()
        {
            string startPath = LastUsedPath;
            if (FileFolderTools.ShowFolderChooser(ref startPath))
            {
                workspace.LoadWorkspace(startPath);
                LastUsedPath = startPath;
            }
            wait = false;
        });
        while(wait){}
    }
Furthermore, although the while(wait) is there, the UI is still responsive, while usually that is not the case when a blocking call is made from a button press. Not sure what is going on here...
EDIT: more extensive stacktrace at the bottom.
Call stack when this.Invoke is called:

Edit - this is what the ShowfolderChooser does (returns true when ok, false on cancel):
 public static bool ShowFolderChooser(ref string path){
        CommonOpenFileDialog dialog = new CommonOpenFileDialog();
        dialog.InitialDirectory = path;
        dialog.IsFolderPicker = true;
        CommonFileDialogResult res = dialog.ShowDialog();
        if (res == CommonFileDialogResult.Ok)
        {
            path = dialog.FileName; //set new path on OK
            return true;
        }
        return false;
    }
Full exception:
This exception was originally thrown at this call stack:
[External Code]
DataManagement.DataManagementCore.Helpers.FileFolderTools.ShowFolderChooser(ref string) in FileFolderTools.cs
Camera._Camera.btn_exportAll_Click(object, System.EventArgs) in Camera.cs
[External Code]
Camera.Program.Main() in Program.cs
But wait...! There's more...
So I've tried putting that code in a separate application and there it works flawlessly. So I guess it is something with my application. One big difference I see is that my Stack frame on the loadWorkspaceToolStripMenuItem_Click has a stack entry user32.dll