how to tell if a COM object has been separated from its underlying RCW without relying on exceptions?
Asked Answered
R

1

7

A way to tell if the COM Object's reference count has reached 0 is by attempting to access one of its members and catch the resulting InvalidComObjectException, which is not very elegant and doesn't seem to lend itself well. Another way is to call Marshal.ReleaseComObject and check the result, but that requires that you decrease the Com Object's reference count by 1.

Is there a straightforward way to tell ?

Ravo answered 19/11, 2013 at 23:37 Comment(0)
A
2

On the .NET forums, this question has been posed before.

Q: Are there any approaches to get the Internal Reference Count without decrementing it?

A: There are no class library methods that can provide this service.

Q: If it's impossible to get the Internal Reference Count without decrementing it, Is there any way to increment its count after calling Marshal.ReleaseComObject()?

A: Again, there are no class library methods that provide this service.

They do have an awkward way of achieving this as a workaround with global APIs exported from your COM server.
Details here: http://social.msdn.microsoft.com/Forums/vstudio/en-US/9de651e0-ad3c-44be-8855-3dc13673ac73/how-can-i-get-the-internal-marshaling-count-of-an-rcw-systemcomobject?forum=clr

Other than that, looks like you are stuck. Hope that helps you.

Ahron answered 20/11, 2013 at 0:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.