Appdomain and assembly in .net Framework
Posted on July 9th, 2009 in .Net Framework |
Appdomain is new application boundary in .net applications. Different appdomains can run in a single process,they can share assemblies or they can keep assemblies for their own.
By default ,every appdomain should load assemblies they needed,they don’t share them.To change this,we can put a LoaderOptimizationAttribute on the entry function of the application ,It can be assigned with any of the following LoaderOptimization enumeration
1.SingleDomain each appdomain has their own assemblies(they share nothing)
2.MultiDomain they try to share as many as they can (a assembly that can be share by different appdomain must be domain neutral)
3.MultiDomainHost only assemblies load from GAC is shared cross appdomain.
some caution:
1.Assemblies load by using Assembly.Load() or LoadFrom() method can not be shared.
2.All the dependencies of an assembly must be located and loaded when the assembly is loaded domain-neutral, because a dependency that cannot be loaded domain-neutral prevents the assembly from being loaded domain-neutral.
3.Each appdomain has its own static data ,when using a shared assembly.
4.An shared assembly could be jit-compiled more times when the appdomain who shared the assembly has different security rights.