Search code examples
vb.netassembliesloadingfile-locking

How to avoid Assembly.LoadFrom blocking?


I create a .net dll on the fly with codedom then I load it with Assembly.LoadFrom like this:

Private Sub Test()
    Dim ASM As Assembly = Assembly.LoadFrom("test.dll")
'Do some stuff with the loaded assembly...
End Sub

it works only once. If I try to recompile the test.dll i get the error that the file is used and not writable. I tried to set ASM to nothing - how can I unload the loaded Assembly from the memory?


Solution

  • Loaded assemblies can only be unloaded by destroying the AppDomain in which they are loaded. Review the How To article links on this MSDN Library page.