How to unload an assembly

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
 
C

Colin Neller

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
 
F

Fabio Cannizzo

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...
 
W

Willy Denoyette [MVP]

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.
 
F

Fabio Cannizzo

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.
 
W

Willy Denoyette [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top