error when outlook exists

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

error when outlook exists
 
Johnnyxp64




Posts: 87
Joined: 2011-05-13
sometimes i get this, but i can't catch it in debug mode to see what is going one and where it crushes.

Exception Source: mscorlib
Exception Type: System.Runtime.InteropServices.InvalidComObjectException
Exception Message: COM object that has been separated from its underlying RCW cannot be used.
Exception Target Site: GetIUnknownForObjectNative

---- Stack Trace ----
System.Runtime.InteropServices.Marshal.GetIUnknownForObjectNative(o As Object, onlyInContext As Boolean)
AddinExpress.OL.2005.dll: N 00000 (0x0) JIT
AddinExpress.OL.ADXOlExplorerArguments..ctor(FormsManager As ADXOlFormsManager, ExplorerObj As Object, CodeContext As ADXOlCodeContext)
AddinExpress.OL.2005.dll: N 0187 (0xBB) IL
AddinExpress.OL.OlExplorersEvents_SinkHelper.DoExplorerClose(expl As OlExplorerEvents_BaseLogic)
AddinExpress.OL.2005.dll: N 0051 (0x33) IL



any idea what should i look for?
the only thing extra i have in the addin module is when the addin terminates to run a function that cleans some temp files. i checked that and has no errors or anything else weird in there.
Posted 31 Mar, 2015 10:51:56 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Johnny,

What Outlook version are you using?

It looks like you release the Explorer object in your code. Could you please check how you get it, in what events you use it, and how you release it?


Andrei Smolin
Add-in Express Team Leader
Posted 01 Apr, 2015 04:00:04 Top
Johnnyxp64




Posts: 87
Joined: 2011-05-13
hi Andrei

yeah i forgot to mention theversion details. its Outlook 2010 x64,
i keep the "explorer" in a static module because i need it to use it in when i am opening centered forms (in folder view layout as you call it i think) because there is an opion the user may do a form.close, and then since there are no more instances i couldn't show it, so in your forums i found a solution for that that involves the "applyTO" function and that needs the explorer object. but at the end of my call i always release it.
Posted 01 Apr, 2015 05:36:22 Top
Johnnyxp64




Posts: 87
Joined: 2011-05-13
ok i think i found it i still keep it in another place,
would you recommend use marshal.release to release it properly on the
AddinModule_AddinBeginShutdown sub? is it safe/recommended to do that there?
Posted 01 Apr, 2015 05:46:50 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
If you get it using ADXOlForm.ExplorerObj, then you must not release it at all. It looks like the issue occurs because you release it.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Apr, 2015 05:54:29 Top
Johnnyxp64




Posts: 87
Joined: 2011-05-13
i get it from this place like that during startup

Private Sub AddinModule_AddinStartupComplete
Common.OutlookExp = Me.OutlookApp.ActiveExplorer




then in my button i use it like that
        Dim explorer As Microsoft.Office.Interop.Outlook._Explorer = CType(Common.OutlookExp, Microsoft.Office.Interop.Outlook._Explorer)
        AddinModule.CurrentInstance.AdxOlFormsCollectionItem2.ApplyTo(explorer)
        Marshal.ReleaseComObject(explorer)



so i do not release the Common.OutlookExp

so what should i do, release it or even not release the other exloper object i am creating to open the closed form?
because one of your team suggested that the code for the closed form should be releasing the object. you always do that in many cases like after attachments, after recepients etc
Posted 01 Apr, 2015 06:14:41 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Johnnyxp64 writes:
so i do not release the Common.OutlookExp


On the contrary, you do release it!

Dim explorer As Microsoft.Office.Interop.Outlook._Explorer = CType(Common.OutlookExp, Microsoft.Office.Interop.Outlook._Explorer)

Executing this code line ends with explorer and Common.OutlookExp pointing to the same COM object!


Andrei Smolin
Add-in Express Team Leader
Posted 01 Apr, 2015 06:41:02 Top
Johnnyxp64




Posts: 87
Joined: 2011-05-13
oh i thought it was byval not byref the ctype, so now those 2 are the 1 and same object.(/facepalm)
hmmm

how to you recommend i should handle this scenario then? just get it when i need it in my button then release it, or remove the release from the button?

thanks
Posted 01 Apr, 2015 06:44:26 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
We recommend that you don't store a COM object globally. Instead, you can get that COM object when you actually need it. Then you use it and release it.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Apr, 2015 06:56:08 Top
Johnnyxp64




Posts: 87
Joined: 2011-05-13
thanks i will go with that.
Posted 01 Apr, 2015 09:24:54 Top