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)
-------------------------------------------------------------------------
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)
-------------------------------------------------------------------------