0

I'm trying to follow and combine 2 example projects from Microsoft:

https://learn.microsoft.com/en-us/visualstudio/vsto/walkthrough-synchronizing-a-custom-task-pane-with-a-ribbon-button?view=vs-2019

and

https://learn.microsoft.com/en-us/visualstudio/vsto/walkthrough-displaying-custom-task-panes-with-e-mail-messages-in-outlook?view=vs-2019

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;

1 Answer 1

1

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)
{
    ...
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. Went on a little adventure but was able to rewrite a solid chunk of code to make it work. Now to figure out how to access a mailitem from the main explorer window.
Either Explorer.Selection collection or Explorer.ActiveInlineResponse depending on what you are actually after.
Actually found another thread where they mentioned you specifically. It was someone looking for the ActiveInlineResponse haha. Thanks, it's all working now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.