Cant unload assembly

A

Andy

Hi,

i tried to load an assembly to an appdomain. The data output is
correctly but the assembly is still in use after unloading the appdomain...

What am I doing wrong?
Please help!


My current code:

-------------------------------------------------------------------------

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

' Application Domain
Dim AppdomainSetup As New AppDomainSetup
Dim baseEvidence As Evidence = AppDomain.CurrentDomain.Evidence
Dim evidence As New Evidence(baseEvidence)
Dim newDomain As AppDomain

' Files
Dim Directory As Directory
Dim ModuleName As String
Dim File As File


ModuleName = "Testmodule.dll"

' Load assembly from file
AppdomainSetup.ApplicationBase = Application.StartupPath

AssemblyToLoad = [Assembly].LoadFrom(ModuleName, evidence)

newDomain = AppDomain.CreateDomain("Module", evidence, AppdomainSetup)

' Load the class library
ClassLibraryModule = AssemblyToLoad.GetModule(ModuleName)

' define start form
ModuleName = Replace(ModuleName, ".dll", "", , , CompareMethod.Text)
FormType = ClassLibraryModule.GetType(ModuleName & ".Frm_Main")

PublicField = FormType.GetField("Build")
msgbox("Current build: " & PublicField.GetValue(PublicField))

newDomain.Unload(newDomain)


-------------------------------------------------------------------------
 
N

Nick Hertl

You loaded the assembly in the default appdomain. If you load the
assembly in the default appdomain it won't get unloaded just because
you unload an appdomain that used it. If you want the assembly to
unload when you unload the appdomain, you will need to load the
assembly only in the appdomain that will be unloaded.
 

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

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top