Why does this code throw an exception during casting? It worked fine previously in ArcGIS 9.3.1.
public void ShowGPWindow(IGPTool tool)
{
IMdElementDialogEvents events;
IMdProcess process = new MdProcessClass();
process.Tool = tool;
IMdElement element = process as IMdElement;
IMdElementDialog toolDialog = new MdDefaultElementDialogClass();
toolDialog.Title = "Jack Dangermond for Life.";
toolDialog.ElementEditor = toolDialog.GetDefaultElementEditor(process);
toolDialog.SetButtons(esriElementDialogButtonType.esriOkCancel);
toolDialog.Show(m_application.hWnd);
events = (IMdElementDialogEvents)toolDialog;
I get a InvalidCastException, and through intellitrace the error is:
Exception:Thrown: "Unable to cast COM object of type 'ESRI.ArcGIS.GeoprocessingUI.MdDefaultElementDialogClass' to interface type 'ESRI.ArcGIS.GeoprocessingUI.IMdElementDialogEvents'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A2B1583C-00B8-435F-A57C-58956CFB8503}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))." (System.InvalidCastException)
A System.InvalidCastException was thrown: "Unable to cast COM object of type 'ESRI.ArcGIS.GeoprocessingUI.MdDefaultElementDialogClass' to interface type 'ESRI.ArcGIS.GeoprocessingUI.IMdElementDialogEvents'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A2B1583C-00B8-435F-A57C-58956CFB8503}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
According to the documentation MdDefaultElementDialog coclass can be QI'ed to IMdElementDialogEvents, also MdElementDialogEventsHelper has the same issue.=( What am i doing wrong? This seems valid to me.