Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

COM Interop, pure function call on exit

A program written by another company allows for add-ins to be written which communicate via COM interop.

Their program appears to be written in C++, and uses managed code according to Process Explorer.

Our Add-In is written in C#. We compile and register our Add-In as a COM object during compile with Visual Studio.

We found their program will crash on exit with a Pure Function Call error when our Add-In is used.

However, the program will NOT crash if we call Marshal.ReleaseComObject() on every object, and then in the OnDisconnect() method we call GC.Collect(); followed by GC.WaitForPendingFinalizers().

I'm trying to understand why this is.

I did find one comment:

"A common approach for releasing unmanaged objects is to set the RCW reference to null, and call System.GC.Collect followed by System.GC.WaitForPendingFinalizers."

Why would this be necessary to prevent a Pure Function Call error on exit?

Examining the call stack of the crash shows it's attempting to perform some sort of RCW release when it encounters the crash.
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial