Click here to Skip to main content
11,920,377 members (52,769 online)
Rate this:
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

1 solution

Rate this: bad
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.
ielsky 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 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)

  Print Answers RSS
0 OriginalGriff 415
1 phil.o 170
3 F-ES Sitecore 130
4 RyanDev 120
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,805
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web04 | 2.8.151120.1 | Last Updated 12 Feb 2011
Copyright © CodeProject, 1999-2015
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