Jump to content
Xtreme .Net Talk

Unload a Assembly ( dll )


Recommended Posts

Posted

Hi,

 

How can i do to unload a assembly (.dll) ?!?!

I am trying to use AppDomain but i have no progress,

because the main appDomain load the assembly too when the appDomain loads the assembly

Posted

I see that . ..

 

Hi,

 

I see that post

 

But he don't help me much

 

The problem is that when a appDomain, part off main AppDomain, loads a dll the main AppDomain loads the dll too

 

Look this

 

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

 

Public Sub Load(ByVal libraryName As String)

Try

Dim cont As Long

Dim controleDomainApp As AppDomain

If Dir(System.Environment.CurrentDirectory & "\" & libraryName) <> "" Then

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 = "false"

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

 

 

When the appDomain created loads the dll the main appDomain loads the dll too. I don't need this. I like that main appDomain uses the dll loaded by the appDomain created

 

Any sugestion ?!?!?

Posted

Unload a dll

 

Hi

 

yes

 

It's a collection object

 

colecaoNomesDll is a private object, that contains the names of all dll's that are loaded by the class

 

So when I need to unload the dll i know if it is loaded or not, and i can know its identifier in the collection

 

I am trying to create a class that loads and unloads dll

 

Can you helpme ?!??!?!?

 

please

  • *Gurus*
Posted

I don't know if this is what is happening to you, but here is what

MSDN says...

If an assembly is used by multiple domains in a process, the assembly's code (but not its data) can be shared by all domains referencing the assembly. This reduces the amount of memory used at run time. ... An assembly is said to be domain-neutral when its code can be shared by all domains in the process. The runtime host decides whether to load assemblies as domain-neutral when it loads the runtime into a process.

You might be able to force this by setting the LoaderOptimization

member of the AppDomainSetup to a LoaderOptimizationAttribute

object with the value of SingleDomain. Maybe...

setup.LoaderOptimization = SingleDomain

The only reason I can see for loading dll assemblies into other

domains is so that they can be unloaded by unloading the domain.

Are you unloading the domain somewhere else?

Posted

Hi

 

What I have to do this that you say . . .

 

"The only reason I can see for loading dll assemblies into other

domains is so that they can be unloaded by unloading the domain."

 

. . . I want to unload a assembly unloading a domain

 

I Really need to do this.

 

I can load and unload a assembly in a domain

But, when I load the assembly in the appDomain created only to load the assembly my main domain loads the assembly too . . .

In other words . . .

I load the assembly two times

One in the domain created

And another in the main domain

 

What can i do to load the assembly one time and share this assembly to all domains that needs this assembly ?

 

I want this . ..

 

"An assembly is said to be domain-neutral when its code can be shared by all domains in the process. "

 

I try to use the LoaderOptimization = SingleDomain

But i have no success . . .

 

So

 

Any sugestion ?!?!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...