Re: .NET Component called from COM Component not released

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



A couple or three ideas in no particular order.

piLogger=NULL;
I haven't stepped through that or looked at the code - does it call Release
on the wrapped interface pointer?

In the Console.NET client - see if Marshal.ReleaseComObject helps release
from the bottom up.

In the ATL component, if you want to free idle DLLs, see if
CoFreeUnusedLibraries helps.

You won't get Dispose called - who's going to call it? I don't believe that
COM client wrappers look for IDisposable, so if it's important expose it as
a method.

--
Phil Wilson [MVP Windows Installer]
----
"wschaub" <wschaub@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:54027790-005E-478A-ADAB-A988D1A7AA2B@xxxxxxxxxxxxxxxx
> We have a test environment in which we instantiate a COM/ATL/C++ component
> from a Managed/Console/.NET/C# application. The COM component in turn
> instantiates and calls a .NET/C#/Class Library component using Interop as
> below:
>
> #import "demologger.tlb" raw_interfaces_only named_guids no_namespace
> // log using .NET Interop
> CComPtr<IDemoLogger> pILogger;
> bstr_t bstrMessage = "Hello from COM to .NET";
>
> hResult = pILogger.CoCreateInstance ( CLSID_DemoLogger,
> NULL,
> CLSCTX_SERVER );
> if ( 0 == hResult ) pILogger->LogToFile ( bstrMessage );
> else return S_FALSE;
>
> // We are done
> pILogger = NULL;
>
> Even if this logic and the CComPtr go out of scope and the reference count
> is decremented, neither the destructor or the Dispose methods of the .NET
> component are called. How can we ensure/enforce disposal or components
> used
> via Interop?
>
> Flow is:
>
> Console/.NET ---> COM/ATL component ---> .NET Component


.



Relevant Pages

  • Re: .NET Component called from COM Component not released
    ... > // log using .NET Interop ... > pILogger = NULL; ... neither the destructor or the Dispose methods of the .NET ...
    (microsoft.public.dotnet.framework.interop)
  • .NET Component called from COM Component not released
    ... // log using .NET Interop ... CComPtrpILogger; ... neither the destructor or the Dispose methods of the .NET ...
    (microsoft.public.dotnet.framework.interop)
  • Re: P/Invoke - Abstract C++ Class
    ... > I've got an c++ class we need to use via interop. ... > this type to dispose properly and this poses a big problem for me at the ... Don't try to interop with unmanaged C++ Classes, just write a simple wrapper ... > public void Dispose ...
    (microsoft.public.dotnet.framework.interop)
  • Re: COM Componente/ COM Objekt unter C# erstellen ?
    ... ist die Funktionen dieser Komponente später in Visual Basic Script zu nutzen. ... [.NET Interop: Get Ready for Microsoft .NET by Using Wrappers to Interact with COM-based Applications] ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Dispose must be thread-safe ?
    ... Two threads are calling Dispose of the same object concurrently; ... *can* be the finalizer thread. ... > tracking (possible concurrent execution of Dispose and Finalize); ... behaviour) the finalizer and Dispose methods being run concurrently ...
    (microsoft.public.dotnet.framework.clr)