How to unload an assembly

  • Thread starter Thread starter Fabio Cannizzo
  • Start date Start date
F

Fabio Cannizzo

MyEXE loads myDLL at runtime using Assembly.LoadFile("myDLL.dll").

Then I create an instance of a class contained in MyDLL using Reflection.

When I terminate the debug session of my EXE file, the DLL remains locked
and cannot be overwritten. I can only exit VS and reload.

Is there any command which can force releasing the DLL module? Any idea?

Thanks,
Fabio
 
Fabio,

If you do not have "Process explorer" (PE), download it and run it:
http://www.sysinternals.com/Utilities/ProcessExplorer.html

After running your application, verify that the process that loaded
"myDLL.dll" is shutdown. If PE is visible while the process dies, PE
will indicate it in red. This step is important. I suspect that you
are still debugging the process or that it is not dieing for some
reason.

If the process has indeed shutdown, but the DLL is still locked, use
the "Find" > "Find Handle..." function in PE to determine what is
locking the DLL.

Colin Neller
http://colinneller.com/blog
 
Hi Colin.
That was interesting. myDLL gets loaded into DEVENV (VS) as soon I open the
solution. Even if I do not open the Designer, and I cancel any refernce to
it from the Toolbox. I wonder why is that...
 
Fabio Cannizzo said:
Hi Colin.
That was interesting. myDLL gets loaded into DEVENV (VS) as soon I open
the solution. Even if I do not open the Designer, and I cancel any
refernce to it from the Toolbox. I wonder why is that...

Suppusing you are using VS2005, right?
This is because you are using the "hosting process" to run your code in the
debugger, this process keeps running, even after you quit the application.

Willy.
 
I am using VS2003.
Fabio

Willy Denoyette said:
Suppusing you are using VS2005, right?
This is because you are using the "hosting process" to run your code in
the debugger, this process keeps running, even after you quit the
application.

Willy.
 
Fabio Cannizzo said:
I am using VS2003.
Fabio

Oh I see, what kind of DLL is this? I'm not clear on why DEVENV (vs) would
attach a DLL which is not part of it's toolbox or used by it's designers
(unless this is a bug in vs2003).

Willy.
 
Back
Top