HighTechTalks DotNet Forums  

Unload a dll called via assembly

Dotnet FAQs microsoft.public.dotnet.faqs


Discuss Unload a dll called via assembly in the Dotnet FAQs forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Andy
 
Posts: n/a

Default Unload a dll called via assembly - 09-24-2005 , 11:40 AM






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

Reply With Quote
  #2  
Old   
Chris Taylor
 
Posts: n/a

Default Re: Unload a dll called via assembly - 09-24-2005 , 01:07 PM






Hi Andy,

As you have discovered, you can not unload assemblies. What you can unload
however is an AppDomain,
so what you should do is create a new AppDomain and load the assembly into
the secondary AppDomain.

See: AppDomain.CreateDomain

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor


"Andy" <andy.mail (AT) zwickau-net (DOT) de> wrote

Quote:
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



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.