Unload a dll called via assembly

Discussion in 'ASP .Net' started by Andy, Sep 24, 2005.

  1. Andy

    Andy Guest

    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
    Andy, Sep 24, 2005
    #1
    1. Advertising

  2. Andy

    Chris Taylor Guest

    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" <> wrote in message
    news:...
    > 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
    Chris Taylor, Sep 24, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy

    Cant unload assembly

    Andy, Oct 12, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,827
    Nick Hertl
    Oct 18, 2005
  2. =?Utf-8?B?TWFyemlwYW4=?=

    asp.net code to unload msohev.dll ??

    =?Utf-8?B?TWFyemlwYW4=?=, Jan 24, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,312
    Bruce Barker
    Jan 24, 2006
  3. Anand
    Replies:
    3
    Views:
    865
    Tim Daneliuk
    Nov 8, 2003
  4. Dinesh Reddy N Y

    UnLoad not been called in Web User Control

    Dinesh Reddy N Y, Apr 13, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    125
    Dinesh Reddy N Y
    Apr 13, 2004
  5. Felix
    Replies:
    1
    Views:
    325
    Felix
    Sep 29, 2006
Loading...

Share This Page