开发者

RaceOnRCWCleanup when closing WPF application with COM and "Enable unmanaged code debugging"

开发者 https://www.devze.com 2023-02-15 11:22 出处:网络
During development of my WPF application I suddenly got the seemingly much-dreaded RaceOnRCWCleanup when closing the application while debugging. When executing without debugger attached everything wa

During development of my WPF application I suddenly got the seemingly much-dreaded RaceOnRCWCleanup when closing the application while debugging. When executing without debugger attached everything was normal.

Image and text of the warning message:

RaceOnRCWCleanup when closing WPF application with COM and "Enable unmanaged code debugging"

Managed Debugging Assistant 'RaceOnRCWCleanup' has detected a problem in 'MyEXE'. Additional Information: An attempt has been made to free an RCW that is in use. The RCW is in use on the active thread or another thread. Attempting to free an in-use RCW can cause corruption or data loss.

The stack trace was not very helpful:

   [External Code] 
>   mscoreei.dll!000007fef75c3309()     
    [Frames below may be incorrect and/or missing, no symbols loaded for mscoreei.dll]  
    mscoree.dll!000007fef7655b21()  
    kernel32.dll!0000000077b7f56d()     
    ntdll.dll!0000000077cb2cc1()    

Since the last bigger change I had made prior to the error occuring for the first time was using a COM object from my managed C# code I obviously suspected that OCX (written by me). Searching the net and stackoverflow did not yield any solution.

Then I found out that this only happens when the setting "Enable unmanaged code debugging" is activated. I had done that, because I wanted to debug my OCX written in unmanaged C++, too. Disabling unmanaged code d开发者_运维知识库ebugging made the problem go away immediately.

This happened on Windows 7, Visual Studio 2010 without SP1.

Does anyone have an explanation what is happening here? Is this a bug?

Update: This problem was gone when I installed service pack 1 for Visual Studio 2010.


Not much to go by. However, do ignore this warning if you get it from terminating the debugging session early. It is caused by the MDA noticing a thread ending that has an outstanding COM interface call that's being marshaled. Using Debug + Stop Debugging can certainly trip this warning, it terminates threads.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号