InvalidComObjectException Explanation...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have received an InvalidComObjectException in my code with the message "COM
object that has been separated from its underlying RCW cannot be used".

Can anyone explain (in simple terms) what this is trying to tell me?

By the way, this exception is being raised in the destructor (Finalize
method) of my class when I try to close a connection.

Thank you,

Jason Richmeier
 
Hi

From your description you are trying to call a COM object from .NET. The
calling route is as below.
..NET--->RCW--->COM.

From the error, it seems that you are trying to calling the method of
closeconnection, but at that time the RCW have release all the COM
reference to the COM. So the .NET can not access the COM via RCW which
cause the problem.

I suggest you try to call the closeconnection at a earlier time.


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I think that makes sense (sort of).

If I put the code to close the connection in the Dispose method (which is
called before the object goes out of scope) everything works fine. My
interpretation is that the destructor will not get called until the object is
garbage collected (which occurs long after the object goes out of scope from
my observation). Is this kind of what you are talking about?

By the way, I hope this doesn't sound like to silly of a question but what
is the RCW and what is its purpose in life (I am assuming it is some sort of
a bridge between .NET and COM).

Thank you,

Jason Richmeier
 
Hi

Yes, the destructor will be called by GC in C#, which is the finalize
method.

As your understanding, the RCW is bridge between .NET and unmanaged world.
Because .NET can not call the unmanaged COM directly.
The whole name of RCW is runtime called wrapper.
Runtime Callable Wrapper
http://msdn2.microsoft.com/en-us/library/8bwh56xe.aspx

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top