I'm trying to follow and combine 2 example projects from Microsoft:
and
I want to have a custom tab on the main outlook window (Reading Pane) (explorer?) which works. And I want to have a taskpane with buttons that modify the current reply / forward email message. I also want this available when someone double clicks an email which brings up the pop-up compose window.
It all works great when going through the pop-up compose window. but it fails when going through the main Outlook Reading Pane (explorer??).
This is the error I recieve when trying to show / hide the taskpane on the main outlook window.
System.InvalidCastException: 'Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.Inspector'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063005-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).'
This is the line causing the exception
Outlook.Inspector inspector = (Outlook.Inspector)e.Control.Context;
You need to cast e.Control.Context
to Outlook.Explorer
instead. Also, you might want to use the "as
" operator - it does not raise an exception, and you can check the return value for null:
Outlook.Explorer explorer = e.Control.Context as Outlook.Explorer;
if (explorer != null)
{
...
}
User contributions licensed under CC BY-SA 3.0