本文介绍了“不能使用已与其基础RCW分离的COM对象”。例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

大家好。



我的申请中有一些奇怪的情况(MS Outlook Addin)。



我在Item.Open事件处理程序中使用MailItem对象。

我得到Inspector对象调用MailItem.GetInspector属性。

当我尝试为Inspector.Close事件设置处理程序时抛出InvalidComObjectException,并显示消息已与基础RCW分离的COM对象无法使用。



代码段:

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





在我看来,这是不可能的情况。获取Inspector并使用它之间没有任何 Marshal.ReleaseComObject 的调用。



此错误非常复制很少,所以在调试时我无法抓住它。



有什么建议吗?



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?

推荐答案


MailItem mailItem;
CloseEvent closeEvent;
...
InspectorEvents_10_Event inspectorEvents = mailItem.GetInspector;
closeEvent = inspectorEvents.Close;
closeEvent += delegate {.....};


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.Here is my mailbox:[email protected]


这篇关于“不能使用已与其基础RCW分离的COM对象”。例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 00:29