InvalidComObjectException exception

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

InvalidComObjectException exception
 
Rafal Piotrowski




Posts: 12
Joined: 2005-08-26
I get a lot this exception. I don't know what it means??? Does any of you has an idea?

System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW can not be used.
at MyAddIn.AddinModule.DoWindowActivate(Object wn) in C:\MyAddIn\AddinModule.vb:line 505
at MyAddIn.AddinModule.adxWordEvents_WindowActivate(Object
sender, Object hostObj, Object window) in C:\MyAddIn\AddinModule.vb:line 501
at AddinExpress.MSO.ADXWordAppEvents.DoWindowActivate(Object doc, Object
wn)


Thanks a lot,
/rp
Posted 26 Aug, 2005 04:05:06 Top
Sven Heitmann




Posts: 193
Joined: 2004-08-23
It seems the Application Object of Word was released.
Have You done somethin like ReleaseComObject() with an Object of type Word.Application?

If yes, remove it :)

I suggest to use the HostApplication Object ADX provides to work with
(if you not using it already).
This Object is released from ADX so don't have to bother with it.

All other Object should be Released by you to prevent memory leaks.
See System.Runtime.InteropServices.Marshal::ReleaseComObject(Object)

e.g.
Dim oDocs as Word.Documents
Set oDocs = HostApplication.Documents

ReleaseComObject(oDocs)
Set oDocs = Nothing
Best regards,

Sven Heitmann
Posted 26 Aug, 2005 05:11:10 Top
Sergey Grischenko


Add-in Express team


Posts: 7202
Joined: 2004-07-05
Hi Rafal.

Do you have any code in the WindowActivate event handler?
If so, probably you release the "hostObj" or "window" parameters in the code. Don't do it because ADX does it itself.
Posted 30 Aug, 2005 01:04:35 Top
Rafal Piotrowski




Posts: 12
Joined: 2005-08-26
Yes I do. In fact I based by plugin on yours Toys example plugin and placed exactly the same code in this event.

regards
rp
Posted 02 Sep, 2005 08:12:23 Top
Sergey Grischenko


Add-in Express team


Posts: 7202
Joined: 2004-07-05
Hi Rafal.

Do you have the "Marshal.ReleaseComObject(wnObj)" line in the WindowActivate event handler? If so, then delete it. Probably the cause of the problem is in this line.
I think I need to review the code of ADX Toys.
Posted 02 Sep, 2005 09:56:02 Top
Sergey Grischenko


Add-in Express team


Posts: 7202
Joined: 2004-07-05
Also I found a little bug in ADX Toys for Word. Change the DoDocumentChange procedure as shown below:

Public Sub DoDocumentChange()
Dim activeWindow As Word.Window
Try
activeWindow = WordHost().ActiveWindow
Catch
End Try
If Not (activeWindow Is Nothing) Then
DoSelectionChange(activeWindow.Selection)
Marshal.ReleaseComObject(activeWindow)
End If
End Sub
Posted 02 Sep, 2005 10:10:31 Top