Hello Mike,
I suppose, the dialog returned by FindCurrentDialog() is not belonging directly to mainDialog. Possibly, it is a sub dialog of another dialog belonging to mainDialog. Try following code. It contains two modifications (1) it verifies whether the found dialog is belonging directly to mainDialog and (2) dismisses the dialog correctly in context of its Owner:
var Core::Group existingDialog = mainDialog.FindCurrentDialog();
// (1)
if ( existingDialog.Owner != mainDialog )
trace "This is some sub dialog";
// (2)
existingDialog.Owner.DismissDialog( existingDialog, null, null, null, null, null, false );
...
The above code should help to better analyse and explain the possible background of the problem. Now let me address how to solve it. I have understood, you want to replace the active dialog existing in mainDialog by a new Whatever_Dialog. Since the method FindCurrentDialog() searches all dialogs recursively, it may return one of the sub...sub dialogs. To find the active dialog existing directly within the mainDialog you use better the method GetDialogAtIndex() with 0 as parameter. Try following:
var Core::Group existingDialog = mainDialog.GetDialogAtIndex(0);
if ( existingDialog != null )
mainDialog.DismissDialog( existingDialog, null, null, null, null, null, false );
...
I hope it helps you further.
Best regards
Paul Banach