Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / April 2004

Tip: Looking for answers? Try searching our database.

Is this .NET Problem?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ramesh K - 12 Apr 2004 11:55 GMT
Hi All,
   During Attach to a process like DLLHOST ,DLLHOST has FILE references to
the system dlls like " odbc32.dll etc..(One can observer this in process
explorer tool of Sysinternals.com by selecting the "View Handles" from the
View menu)

But during the Detach process same handles are not getting released by the
DLLHOST process.WHY?

My application has a requirement that the custom dlls loadded into DLLHOST
can be unloaded(using cofreeunsued libraries) and modified whenever needed,
because of the above problem unakbe to update the custom dll.

steps to be folowed to simuate the problem.
Step1) create a C++ COM component named "A" and another C++ COM component
named "B" which creates "A" upon a method invocation let us say
CreateMe().Add another method in "B" to unload the component "A" letus say
KillMe()..in this method release the "A" reference and call
CoFreeUnUsedLibraries() so that "A" is unloaded.
Step2)Add "B" to DLLHOST using Component services asministrative tool
Step3)create a client application which creates component "B" anc calls
CreateMe() so that "A" is also created.Add another button to call KillMe()
of "B".
Step4)Open "A" in devenv. and attach to the DLLHOST(make sure dbgproxy is
running..as we are debugging Native C++ applicatipn to start this use net
start dgbproxy.exe from .NET command prompt).Now you can debugger loading
systems dll's and custom dlls in the output box..Now open Process
explorer(tool from sysinternals.com) and select teh View Handles option from
View menu..A.dll FILE handle is present here.
Step5)Detach "A" from DLLHOST
Step6)Now click on the button of the client application which calls KillMe()
of "B".Now the "A" DLL is unloaded. BUT Still the FILE reference for "A"
exists under DLLHOST

Any suggestions are welcome.

Regards,
Ramesh
Willy Denoyette [MVP] - 12 Apr 2004 16:13 GMT
CoFreeUnusedLibraries only unloads libraries loaded by explicitely calling
CoLoadLibrary, I guess DllHost loads the libraries by calling
LoadLibrary(Ex) when creating an instance of an object.

Willy.

> Hi All,
>    During Attach to a process like DLLHOST ,DLLHOST has FILE references to
[quoted text clipped - 37 lines]
> Regards,
> Ramesh
Ramesh K - 13 Apr 2004 05:01 GMT
Hi Willy,
   Thanks for the reply.
   That's fine ,but my problem is during Attach DLLHOST holds the FILE
references of the custom & system dll's ,but during Detach these FILE
handles are not     getting reelased. After Detach i do release my custom
pointer and call CoFreeUnUsedLibraries() to  release the Custom DLL for
upgradataion.But as DLLHOST still holding the FILE reference upgradation of
the custom DLL is not possible. I feel either there should be some way to
release the FILE  Handle(which is not recommended) or could be the
design\problem of .NET.

Regards,
Ramesh

> CoFreeUnusedLibraries only unloads libraries loaded by explicitely calling
> CoLoadLibrary, I guess DllHost loads the libraries by calling
[quoted text clipped - 43 lines]
> > Regards,
> > Ramesh
Willy Denoyette [MVP] - 13 Apr 2004 22:00 GMT
Please re-read my reply, CoFreeUnUsedLibraries only unloads libraries loaded
with CoLoadLibrary().
Did you load your libs using CoLoadLibrary? I guess not. And I don't see why
this should be a .NET problem, your libraries are native C++ dll, right?

Willy.

> Hi Willy,
>    Thanks for the reply.
[quoted text clipped - 71 lines]
>> > Regards,
>> > Ramesh
Ramesh K - 14 Apr 2004 04:51 GMT
Hi Willy,
    Thanks fo your reply.
   I understood your reply. But didn't get any solution to my problem.

   My DLL is a native C++ dll, which is created (using CoCreateInstance) by
another COM component configured with COM+. So my C++ component is running
under DLLHOST process & DLLHOST will have a Handle to the DLL. As my C++
Component is already created by the component running under DLLHOST, at
runtime i should be able to debug C++ component by attaching to the DLLHOST
process.

NOTE: My C++ component is already created and it has some state.

So once  i Attach to the DLLHOST process in the process explorer i see FILE
HANDLE reference (not same as the HANDLE to the DLL created during
CoCreateInstance of the C++ component) been added to the DLLHOST process.

Once i am done with debugging i am Detaching the C++ component from the
DLLHOST process. Now i am unloading the C++ component by using
CoFreeUnUsedLibraries() to RELOAD my C++ component with some changes.
CoFreeUnUsedLibraries freeeing the HANDLE created during the
CoCreateInstance, but still the FILE HANDLE created by DLLHOST during the
Attach process exists, because of this when i try to modify the C++
component  by recompiling, it gives error stating that the it cannot
override the dll, as the FILE HANDLE reference is held by the DLLHOST.

If i release the FILE HANDLE reference explicitly using process explorer i
am able to compile my program. As DLLHOST is not releasing the FILE HANDLE
reference i feel it could be problem with .NET.

Please suggest me some solution.

Regards,
Ramesh

> Please re-read my reply, CoFreeUnUsedLibraries only unloads libraries loaded
> with CoLoadLibrary().
[quoted text clipped - 78 lines]
> >> > Regards,
> >> > Ramesh
Willy Denoyette [MVP] - 14 Apr 2004 11:42 GMT
Inline ***

Willy.

> Hi Willy,
>     Thanks fo your reply.
>    I understood your reply. But didn't get any solution to my problem.
>
>    My DLL is a native C++ dll, which is created (using CoCreateInstance)
> by
*** And here CoCreateInstance will call LoadLibrary, not CoLoadLibrary, IMO,
this loaded DLL will not be unloaded when you call CoFreeUnusedLibraries.

> another COM component configured with COM+. So my C++ component is running
> under DLLHOST process & DLLHOST will have a Handle to the DLL. As my C++
[quoted text clipped - 9 lines]
> HANDLE reference (not same as the HANDLE to the DLL created during
> CoCreateInstance of the C++ component) been added to the DLLHOST process.

*** Which file does this HANDLE belongs to?
> Once i am done with debugging i am Detaching the C++ component from the
> DLLHOST process. Now i am unloading the C++ component by using
> CoFreeUnUsedLibraries() to RELOAD my C++ component with some changes.
> CoFreeUnUsedLibraries freeeing the HANDLE created during the
> CoCreateInstance, but still the FILE HANDLE created by DLLHOST during the
> Attach process exists,
*** Again try to find-out which file this handle belongs to.
because of this when i try to modify the C++
> component  by recompiling, it gives error stating that the it cannot
> override the dll, as the FILE HANDLE reference is held by the DLLHOST.
>
> If i release the FILE HANDLE reference explicitly using process explorer i

*** so if you release the handle to this "mysterious" file, you can
overwrite your dll? Seems like this is the handle of your DLL.

> am able to compile my program. As DLLHOST is not releasing the FILE HANDLE
> reference i feel it could be problem with .NET.

*** Sorry but I'm missing the relation with .NET, your components are
unmanaged C++ dll's.

> Please suggest me some solution.

*** Why not stop the COM+ application before you overwrite a DLL?

> Regards,
> Ramesh
Ramesh K - 14 Apr 2004 14:38 GMT
Replies are inline &&&
> Inline ***
>
[quoted text clipped - 8 lines]
> *** And here CoCreateInstance will call LoadLibrary, not CoLoadLibrary, IMO,
> this loaded DLL will not be unloaded when you call CoFreeUnusedLibraries.

   &&&Forgot to mention that we are freeing the Pointer to the object and
then calling CoFreeUnUsedLibraries()..Dll getting released at this point
..able to observer this in Process Explorer.

> > another COM component configured with COM+. So my C++ component is running
> > under DLLHOST process & DLLHOST will have a Handle to the DLL. As my C++
[quoted text clipped - 11 lines]
> >
> *** Which file does this HANDLE belongs to?
&&& Our  C++ Component, which i am debugging by Attahcing to DLLHOST
Process. During Attach to DLLHOST this FILE HANDLE been added to the
DLLHOST. I also found other System dll's which are Attached during the
Attach to DLLHOST.

> > Once i am done with debugging i am Detaching the C++ component from the
> > DLLHOST process. Now i am unloading the C++ component by using
[quoted text clipped - 3 lines]
> > Attach process exists,
> *** Again try to find-out which file this handle belongs to.

&&&Pretty sure that My C++ Component FILE HANLDE alongwith the other System
DLL's.

> because of this when i try to modify the C++
> > component  by recompiling, it gives error stating that the it cannot
[quoted text clipped - 4 lines]
> *** so if you release the handle to this "mysterious" file, you can
> overwrite your dll? Seems like this is the handle of your DLL.

&&& Yes,this is the FILE HANDLE  reference of my C++ component. Also this is
not the HANDLE  TO THE DLL.

> > am able to compile my program. As DLLHOST is not releasing the FILE HANDLE
> > reference i feel it could be problem with .NET.
> >
> *** Sorry but I'm missing the relation with .NET, your components are
> unmanaged C++ dll's.

&&& relation is DLLHOST holds the FILE reference During Attach ..which is
not getting released during Detach from the DLLHOST..

> > Please suggest me some solution.
> >
> *** Why not stop the COM+ application before you overwrite a DLL?

&&&I can't, as my COM+ application hosts other DLL's which should be alive
throughout my application life cycle..Only the exception is my C++ component
loads & unloads during the application life cycle.

> > Regards,
> > Ramesh

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.