Error in Outlook 2013 inline response mailitem after upgrading AddinExpress.MSO.2005.dll to 7.7.4087.2005

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

Error in Outlook 2013 inline response mailitem after upgrading AddinExpress.MSO.2005.dll to 7.7.4087.2005
COM object that has been separated from its underlying RCW cannot be used 
Igor Govorov




Posts: 83
Joined: 2014-02-12
Hi support,

I've upgraded AddinExpress.MSO.2005.dll
from version: 7.6.4084.2005
to version: 7.7.4087.2005

After this I started to get an error on accessing mailitem when handling events from ADXOutlookItemEvents and also when work with mailitem from a ribbon button.

This looks like a degradation and replacing this dll to the old version solves this error.

Thanks!


Error examples:

System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at SI.Documents.Office.MS.Outlook.Wrappers.MailItemWrapper.get_MailItemObject() in e:\Dev\Branches\trunk_pkg\Common\Documents\Office.MS\Outlook\Wrappers\MailItemWrapper.cs:line 19
at SI.Documents.Office.MS.Outlook.Wrappers.MailItemWrapper.get_Sent() in e:\Dev\Branches\trunk_pkg\Common\Documents\Office.MS\Outlook\Wrappers\MailItemWrapper.cs:line 88
at SI.IQP.Agent.Office.Outlook.Lib.OutlookAddInHelper.Item_BeforeSave(ItemEventHandler handler, Boolean& cancel) in e:\Dev\Branches\trunk_pkg\IQP\Agent\Office\Outlook\Lib\OutlookAddInHelper.cs:line 815
at SI.IQP.Agent.Office.Outlook.Lib.ItemEventHandler.OnWrite(Boolean& cancel) in e:\Dev\Branches\trunk_pkg\IQP\Agent\Office\Outlook\Lib\Handlers\ItemEventHandler.cs:line 49
at SI.IQP.Agent.Office.Outlook.Lib.OutlookItemEventsHandler.ProcessWrite(ADXCancelEventArgs e) in e:\Dev\Branches\trunk_pkg\IQP\Agent\Office\Outlook\Lib\Handlers\OutlookItemEventsHandler.cs:line 26
at AddinExpress.MSO.ADXOlItemEvents_10_SinkHelper.AddinExpress.MSO.IOutlookItemEvents_10.Write(Boolean& cancel) in c:\work\Secure1\vendor\AddInExpress\ADXLib\ADXHostSinkHelpers.cs:line 2315


OR:

System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at SI.Documents.Office.MS.Outlook.Wrappers.MailItemWrapper.get_MailItemObject() in e:\Dev\Branches\trunk_pkg\Common\Documents\Office.MS\Outlook\Wrappers\MailItemWrapper.cs:line 19
at SI.Documents.Office.MS.Outlook.Wrappers.MailItemWrapper.get_Saved() in e:\Dev\Branches\trunk_pkg\Common\Documents\Office.MS\Outlook\Wrappers\MailItemWrapper.cs:line 83
Posted 15 Apr, 2015 09:54:32 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Thank you for letting us know. We are looking into this.


Andrei Smolin
Add-in Express Team Leader
Posted 15 Apr, 2015 10:01:27 Top
Igor Govorov




Posts: 83
Joined: 2014-02-12
Great!
Thanks Andrei.
When is the next planned update?
Posted 15 Apr, 2015 10:29:13 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
I cannot tell at the moment. We need to complete the research.


Andrei Smolin
Add-in Express Team Leader
Posted 15 Apr, 2015 10:30:36 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Igor,

I suppose that you've run into this problems because you cache the MailItem passed to you in the ExplorerInLineResponse or BeforeItemPaste event. If so, the problem is caused by version 7.7 releasing this object after you handle these events; previous versions didn't release the COM objects and it was wrong.

Below is a workaround that allows you to use a COM object outside of the event handler. Note however that caching COM objects requires that you trace all appropriate events to release the COM object. Failing to do so may end with a crash if your code accesses the cached COM object after Outlook destroyed its objects.

bool incrementReferenceCounter = true;
Outlook.MailItem mail = null;

private void adxOutlookEvents_ExplorerInlineResponse(object sender, object itemObject) {
    object result = null;
    if (incrementReferenceCounter == false) {
        result = itemObject;
    } else {
        IntPtr theIUknown = Marshal.GetIUnknownForObject(itemObject);
        Marshal.AddRef(theIUknown);
        result = Marshal.GetObjectForIUnknown(theIUknown);
    }
    mail = result as Outlook.MailItem;
}

private void adxRibbonButton7_OnClick(object sender, IRibbonControl control, bool pressed) {
    MessageBox.Show(mail.Subject);
    //Marshal.ReleaseComObject(mail);
}


If incrementReferenceCounter is false, adxRibbonButton7_OnClick produces InvalidComObjectException. If incrementReferenceCounter is true, adxRibbonButton7_OnClick works okay.


Andrei Smolin
Add-in Express Team Leader
Posted 16 Apr, 2015 09:50:02 Top