Home All Groups Group Topic Archive Search About

.NET 3.5 - System.Reflection.Assembly does not release object (DLL) after use

Author
1 Apr 2010 1:20 AM
Wolfixx
Hello,

Does anyone of you know how I can force vb.net to remove the handle of a
local DLL which I used beforehand with Reflection.

Here is a fragment of the code.
I have a base class and a derived class. This app only knows the base class
and creates an Instance of the derived class by using Reflection which works
fine. The only problem I have is that the local DLL file is blocked (I can't
delete it) as long as I don't close the Application

            Dim GetCustomModule as BaseClass
            Dim dll As Assembly =
Assembly.LoadFrom("c:\tools\DerivedCass.dll")
            For Each assemblytype As System.Type In dll.GetExportedTypes
                If assemblytype.ToString = "tools" Then
                    GetCustomModule =
DirectCast(Activator.CreateInstance(assemblytype), BaseClass)
                End If
            Next
....
do something with the Class and then get rid of it
....

            dll = Nothing
'now the file c:\tools\DerivedCass.dll is still locked and I can't delete
it.

Forcing Garbage Collector to run doesn't help at all. I can see through
Sysinternals\ProcessExplorer that AppName.vshost.exe has still a handle on
that file.

Thanks for any help
Wolfgang

Author
1 Apr 2010 2:16 AM
Armin Zingler
Am 01.04.2010 03:20, schrieb Wolfixx:
> Hello,
>
> Does anyone of you know how I can force vb.net to remove the handle of a
> local DLL which I used beforehand with Reflection.

Look at the big "Note" in the middle:
http://msdn.microsoft.com/en-us/library/2bh4z9hs.aspx

I've no experience with it but maybe you find something
in the neighbour topics (about assemblies and application domains).

--
Armin
Author
9 Apr 2010 4:27 AM
Wolfixx
Show quote Hide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:O$Kj#sY0KHA.776@TK2MSFTNGP04.phx.gbl...
> Am 01.04.2010 03:20, schrieb Wolfixx:
>> Hello,
>>
>> Does anyone of you know how I can force vb.net to remove the handle of a
>> local DLL which I used beforehand with Reflection.
>
> Look at the big "Note" in the middle:
> http://msdn.microsoft.com/en-us/library/2bh4z9hs.aspx
>
> I've no experience with it but maybe you find something
> in the neighbour topics (about assemblies and application domains).
>
> --
> Armin

Thanks Armin that seems to be a design limitation then.
Wolfgang