Unload a dll called via assembly

A

Andy

Hi everybody,

i´m working on an application that loads different modules (dll files)
via an assembly.
I check the build version in that dll file and if a newer version
exists, i want to update the file. There´s only one problem: once loaded
the library, i´m not able to delete it while the application is running.

Current function:

Dim AssemblyToLoad As [Assembly]
Dim ClassLibraryModule As [Module]
Dim FormType As Type
Dim AssemblyForm As Form
Dim PublicField As FieldInfo

AssemblyToLoad = [Assembly].LoadFrom(ModuleName)
ClassLibraryModule = AssemblyToLoad.GetModule(ModuleName)

FormType = ClassLibraryModule.GetType(ModuleName & ".ClassMain")

PublicField = FormType.GetField("VersionBuild")

return PublicField.GetValue(PublicField))

Application.DoEvents()

If the return value of the function is smaller as the VersionBuild of
the server dll, the dll file should be updated. But as long as the
program is running, the dll file is write protected.

How can i unload the assembly so the dll file isnt write protected anymore?

Please help!
Thanks, Andy
 
O

Ollie Riches

You can unload an assembly from a .Net application but only by unloading the
appDomain that the assembly is loaded into. So if you don't create a
seperate appDomain when you are dynamically loading your assemblies you
won't be able to unload the assemblies.

check out the following links I found on google:

http://blogs.msdn.com/suzcook/archive/2003/07/08/57211.aspx

As the blog says:

'...Maybe you don't need to load that Assembly, anyway. If you just need
info about it, you could call AssemblyName.GetAssemblyName() with the path
to the file...'

HTH

Ollie Riches
 

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