Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i Unload a Assembly ?

Status
Not open for further replies.

CAPSKOL

Programmer
Sep 4, 2002
3
BR
Hi there

How can i Unload a Assembly ? ( .dll )

I try to create a appDomain and load the assembly there.
But the main program loads the assembly too
:(

How can i do this. With the main program not loading the assembly ?!?!?
 
I know that it's impossible to unload a assembly. Only the appDomain . . .

But
I need to load and unload a assembly . . .

I am trying to do this . . .
------------------ cut here --------------------------
Public Sub Load(ByVal libraryName As String)
Try
Dim cont As Long
Dim controleDomainApp As AppDomain
If Dir(System.Environment.CurrentDirectory & &quot;\&quot; & libraryName) <> &quot;&quot; Then
' Checando se a dll ja nao esta carregada.
For cont = 1 To colecaoNomesDLL.Count
If colecaoNomesDLL(cont) = libraryName Then
Exit Sub
End If
Next
colecaoNomesDLL.Add(libraryName)
Dim setup As AppDomainSetup = New AppDomainSetup()
setup.ApplicationBase = System.Environment.CurrentDirectory
setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory
setup.ShadowCopyFiles = &quot;false&quot;
setup.ShadowCopyDirectories = libraryName
controleDomainApp = AppDomain.CreateDomain(libraryName, Nothing, setup)
controleDomainApp.Load(System.Reflection.AssemblyName.GetAssemblyName(libraryName))
colecaoAppDomain.Add(controleDomainApp)
End If
Catch err As Exception
tratadorErro.trataErro(err)
End Try
End Sub
------------------ cut here --------------------------
This method to load a assembly
And this to unload a assembly
------------------ cut here --------------------------
Public Sub Unload(ByVal libraryName As String)
Try
Dim cont As Integer
' Checando se a dll ja nao esta carregada.
For cont = 1 To colecaoNomesDLL.Count
If colecaoNomesDLL(cont) = libraryName Then
AppDomain.Unload(colecaoAppDomain(cont))
colecaoAppDomain.Remove(cont)
colecaoNomesDLL.Remove(cont)
GC.Collect()
Exit Sub
End If
Next
Catch err As Exception
tratadorErro.trataErro(err)
End Try
End Sub

------------------ cut here --------------------------

But, in the method load, the main AppDomain loads the assembly too . . .
How can i do to the AppDomain not load the assembly, the AppDomain must uses the assembly of other appDomain.

I don't know if you understand this . . .

Anyway

Tks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top