Object mouse and command not "properly" released?

Valued Contributor
Valued Contributor

 

Hi,

Sometime ago, i downloaded a sample of  command and mouse objects named PickDrawingView,  written in VB.Net provided in this forum.

I tried out and it seems to work fine, although when it reaches the release of the objects in the m_command_terminate event if i catch a exception i get the following:

message  "Exception as been thrown by the target of an invocation" 

innerexception message "COM object that is been separated from its underlying RCW cannot be used"

I put some breakpoints and it seems to get the error in the m_mouse=nothing statement.

I'm using sev20.00.10.03 and VB.net 2005,

My questions are:

Why is this happening?

It's a problem not to set the objects to nothing after releasing them?

If it's a problem, what can i do to fix this?

Thanks for sharing your knowledge in this forum.

 

Posted by: Luis Azevedo
Post date: 1/30/2009 11:45:30 AM

2 REPLIES

RE: Object mouse and command not "properly" released?

Valued Contributor
Valued Contributor

Posted By Peixe on 01/30/2009 5:45 PM

 

Hi,

Sometime ago, i downloaded a sample of  command and mouse objects named PickDrawingView,  written in VB.Net provided in this forum.

I tried out and it seems to work fine, although when it reaches the release of the objects in the m_command_terminate event if i catch a exception i get the following:

message  "Exception as been thrown by the target of an invocation" 

innerexception message "COM object that is been separated from its underlying RCW cannot be used"

I put some breakpoints and it seems to get the error in the m_mouse=nothing statement.

I'm using sev20.00.10.03 and VB.net 2005,

My questions are:

Why is this happening?

It's a problem not to set the objects to nothing after releasing them?

If it's a problem, what can i do to fix this?

Thanks for sharing your knowledge in this forum.

 

Peixe,

VB6 could work with COM objects natively.  VB.NET interacts with COM objects via Runtime Callable Wrapper (RCW).  Consequently, working with COM is much more difficult in .NET.  COM used deterministic release of objects whereas .NET uses non-deterministic Garbage Collection (GC).

So in VB6, you could Set objCOM = Nothing and the object was released.  In .NET, when you Set objCOM = Nothing, you are simply marking the object "eligible" for collection and you don't know when it's going to be released.  We do have Marshal.ReleaseComObject() but again, it does not "truely" release the COM reference.

In your case, your object is somehow being freed and collected before you're done.  I'd really need to see your entire project to determine what's going on.

 

Posted by: Jason Newell
Post date: 1/31/2009 3:47:47 PM

RE: Object mouse and command not "properly" released?

Valued Contributor
Valued Contributor

 

Jason,

In attachment  you can find the sample project that i download with some added code just for debugging. I made some comments in there.

This project hasn´t the message filter implemented so i get the exception "CALL WAS REJECTED BY THE CALLEE", but i found the workaround for this problem in this forum. 

I'll have a close look of the links that you mentioned at  your reply and If i have any advance in this matter i'll post it here.

Thank you for all your help.

 

 

Posted by: Luis Azevedo
Post date: 2/1/2009 9:45:54 AM