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)


-------------------------------------------------------------------------
 
D

David Levine

You have to wrap all accesses to the other assembly within a remoted object
running in the context of the second appdomain.
 
A

Andy

Hi,

sorry, but i couldn't follow your advice. Could you explain that to me
stricter?

Thanks,
Andy

David said:
You have to wrap all accesses to the other assembly within a remoted object
running in the context of the second appdomain.

Andy said:
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)


-------------------------------------------------------------------------
 
D

David Levine

This link does a pretty good job of explaining the basic concepts.
http://www.gotdotnet.com/team/clr/AppdomainFAQ.aspx


Andy said:
Hi,

sorry, but i couldn't follow your advice. Could you explain that to me
stricter?

Thanks,
Andy

David said:
You have to wrap all accesses to the other assembly within a remoted
object running in the context of the second appdomain.

Andy said:
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)


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

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