Reflection and Closing files

Guardian

Active member
Joined
Jan 19, 2005
Messages
44
Location
England
Programming Experience
5-10
Hey, im having a major headache trying to get this to work:

VB.NET:
If IO.File.Exists(ffbSelect.Text) Then   'continue if the file exists

    If mnuOptionsCopyLocal.Checked = True Then
        Dim nPath As String = Application.StartupPath & "\testing.dll"

        IO.File.Copy(path, nPath, True)
        path = nPath

    End If

    Dim extAssembly As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile(path)
    
    'reflection stuff
    
    'Added to see if this would close the file....it doesnt
    If extAssembly IsNot Nothing Then
        extAssembly = Nothing
    End If

End If

my problem is that the second time this is called the file is in use, and as far as i can tell (i have done a lot of searching) you cannot close the file when done with it.

any ideas/solutions? or have i missed something really obvious?
 
You can't unload an assembly loaded into the AppDomain, but you can read the bytes of the file and load the assembly from these bytes, this will not lock the file.
 
or My.Computer.Filesystem.ReadAllBytes
 
Back
Top