Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello Everybody.
 
I have strange situation in my applicaion (MS Outlook Addin).
 
I work with MailItem object in Item.Open event handler.
I get Inspector object calling MailItem.GetInspector property.
When I try to set handler for Inspector.Close event InvalidComObjectException with message "COM object that has been separated from its underlying RCW cannot be used" is thrown.
 
Code snippet:
MailItem mailItem;
...
InspectorEvents_10_Event inspectorEvents = mailItem.GetInspector;
inspectorEvents.Close += delegate {.....}; //Exception occurs
 
In my opinion, it is impossible situation. There is no any call of Marshal.ReleaseComObject between getting Inspector and using it.
 
This error is reproduced very rarely, so I can't catch it while debugging.
 
Any suggestions?
Posted 1-Feb-11 8:44am
ielsky206

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

One likely cause is that you are accessing a single threaded COM object from different threads. In your case, the event handler may not be running on the thread that created the COM object.
  Permalink  
Comments
ielsky at 2-Feb-11 12:52pm
   
Thank you for you answer.
 
I checked application log. Thread id in the place where error occurs is the same as thread id in NewInspector handler (where we get Inspector). So, I need another idea.
ncc01 at 12-Feb-11 3:09am
   
Hi, I am facing the same problem it is really difficult to debug it because the test case is not unique. did you find a solution? I really appreciate your help in advance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 12 Feb 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100