all groups > dotnet interop > march 2005 >
You're in the

dotnet interop

group:

Interop COM in C# - can't get the object released


Interop COM in C# - can't get the object released Alan
3/25/2005 11:09:03 AM
dotnet interop:
I am trying to develop an ATL COM object together with a C# web
application that will host it. I am following the COM Interop Part 1: C#
Client Tutorial, Example 2, The C# Code Approach from the April 2004
MSDN library exactly. But the client will not release the COM object.

The COM object is being run in its own solution and under a separate
instance of Visual Studio .NET 2003. At this point the object consists
only of the constructor, FinalConstruct, and FinalRelease. No methods or
properties have been implemented on the interface.

The C# client is the corresponding code according to the tutorial and is
in the code-behind of a .NET web form. No methods or properties on the
interface.

However, after I have run the simple

MyCOMTypeLib.MyCOMManager manager = new MyCOMTypeLib.MyCOMManager()

command and have exited either the debugger or the browser independent
of Visual Studio. A reference remains on MyCOM.dll. The dll cannot be
rebuilt and it cannot be deleted. The only way I have found to clear the
reference is to reboot the computer.

Is there a way for force the DLL to be unloaded? When programming ASP,
this could be done by unloading the application with the IIS manager.

Better yet, why is this reference remaining contrary to documentation?



Re: Interop COM in C# - can't get the object released Alan
3/29/2005 6:59:03 AM
Robin,

Thank you for responding.

At this point, the only operation with the COM component is to create it
with 'new'. No interfaces have been called. I tried using
Marshal.ReleaseCOMObject without success.

Alan


[quoted text, click to view]
Re: Interop COM in C# - can't get the object released Alan
3/29/2005 8:23:06 AM
Robin,

At this point the COM object does nothing. It doesn't even have variables
ore interface members yet. Before developing it, I want to make sure I know
how to do the interop correctly, starting from creating and releasing it.

Actually, I think that the problem is in ASPNET. I am using a web
application to develop and debug the COM object. When using ASP, one simply
unloads the application after each debugging run. I don't know how to unload
ASPNET other than to stop and restart w3svc.

Alan

[quoted text, click to view]
Re: Interop COM in C# - can't get the object released Robin Tucker
3/29/2005 3:39:47 PM
How are you releasing the COM components you use (assuming MyCOMManager is a
com component)?

If you have a reference to an interface from COM, you need to
Marshal.ReleaseCOMObject on the instance before you exit.

[quoted text, click to view]

Re: Interop COM in C# - can't get the object released Robin Tucker
3/29/2005 4:47:00 PM
Well, in my experience there is something else to consider. Firstly, if the
COM object is "out of process", it will stay in memory unless it is
explicitly "exited". I know this only from using Microsoft Word interop,
where even if you release all references to the COM object, the image stays
in task manager, so you execute the m_WordApplication.Quit command and it
goes. Perhaps you are out of process and hence also need to implement a
quit command on your object?

[quoted text, click to view]

AddThis Social Bookmark Button