The explorer object is not available exception in "ADXSelectionChange" event handler

Add-in Express™ Support Service
That's what is more important than anything else

The explorer object is not available exception in "ADXSelectionChange" event handler
 
Subscribe
keni zhou




Posts: 13
Joined: 2018-08-22
Dear Sir,

We have encountered the following exception when handle the "ADXSelectionChange" event in some scenario:

at Microsoft.Office.Interop.Outlook._Explorer.get_Selection()
at CMMP.Mail.Outlook.Globals.GetExplorerSelection() in D:\VS2017\source\repos\CMMP.Mail\CMMP.Mail.Outlook\Globals.cs:line 213
2019-07-11 09:25:58.6720 WARN The explorer object is not avaliable at this moment. The Explorer has been closed and cannot be used for further operations. Review your code and restart Outlook.


I would like to know how can I to check if the "explorer" is available? or just to catch the exception?

Thanks,
Keni Zhou.
Posted 15 Jul, 2019 21:42:35 Top
Andrei Smolin


Add-in Express team


Posts: 16466
Joined: 2006-05-11
Hello Keni,

In what scenario do you get this exception? Could you please provide some code for us to see what you do? You can send it to the support email address; see {Add-in Express installation folder}\readme.txt; please make sure your email contains a link to this topic.

What Add-in Express build do you use? Does the issue persist if you turn off all other COM add-ins?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 Jul, 2019 03:20:59 Top
keni zhou




Posts: 13
Joined: 2018-08-22
Dear Andrei,


I have a Outlook Region on the explorer and subscribe its "SelectionChange" event.

For example: I delegated UserA's Inbox to UserB's, then Open userB's inbox folder in UserA's Outlook.



private void MailHeader_ADXSelectionChange()
{
var explorer = Globals.CurrentExplorer;

Selection explorerSelection = null;
try
{
explorerSelection = explorer.Selection;
}
catch (System.Exception ex)
{

ExceptionHandler.SupressException(ex, "the selection object of explorer is not avaliable at this moment.");
}

if (explorerSelection == null)
{
return;
}

using (var selection = explorerSelection.WithComCleanup())
{
if (selection.Resource.Count > 0)
{

object selectedItem = selection.Resource[1];

currentMailItem = selectedItem as MailItem;

if (currentMailItem == null)
{
selectedItem.ReleaseComObject();

Hide();
}
else
{

Clean();
Reset(currentMailItem);
Show();
}


}
else
{
Hide();
}
}



}



Thanks!
Posted 16 Jul, 2019 05:44:04 Top
Andrei Smolin


Add-in Express team


Posts: 16466
Joined: 2006-05-11
Hello Keni,

Try to use this.ExplorerObj as Outlook.Explorer instead of Globals.CurrentExplorer. That property returns an Outlook.Explorer object managed by the form itself; you don't need to release that Explorer object.

Also, Explorer.Selection may produce an exception when in certain folders such as RSS Subscriptions. The complete list of such folders depends on the Outlook version used. Make sure you handle this exception.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 Jul, 2019 06:07:11 Top