Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I Dynamically Load Assemblies Not on Disk into an ASP .Net Web Application?
    primarykey
    data
    text
    <p>I'm writing a prototype to prove the feasibility of something I'm working on. Basically, it requires loading assemblies not on disk into an application domain. On the surface, it sounds easy. In fact, it's child's play in the WinForms world where a process is a process.</p> <p>For the ASP.Net Web Applications, it's a bit squirrelly. I've got it working 99.99%. The current method is somewhat working like this:</p> <pre><code>public class AppDomainManager : System.AppDomainManager { PhantomAssemblyLoader m_phantomAssemblyLoader; public AppDomainManager() { m_phantomAssemblyLoader = new PhantomAssemblyLoader(); } public override void InitializeNewDomain(AppDomainSetup appDomainInfo) { m_phantomAssemblyLoader.Attach(AppDomain.CurrentDomain); } } public class PhantomAssemblyLoader { public PhantomAssemblyLoader() { } public void Attach(AppDomain appDomain) { appDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve); appDomain.DomainUnload += new EventHandler(DomainUnload); } public void Detach(AppDomain appDomain) { appDomain.AssemblyResolve -= AssemblyResolve; appDomain.DomainUnload -= DomainUnload; } void DomainUnload(object sender, EventArgs e) { this.Detach(sender as AppDomain); } private Assembly AssemblyResolve(object sender, ResolveEventArgs args) { Assembly asssembly = Assembly.Load(BlackMagic.GetBytes(sender, args)); return asssembly; } } </code></pre> <p>The problem seems to be that a new AppDomain is instantiated and unloaded for each page load. The above code loads the required assembly, unloads it, loads it again and so on. I know this is happening because the static data within these phantom assemblies does not persist between page loads.</p> <p>The correct solution can load these phantom assemblies into the same context as those assemblies found in the /bin folder. These are loaded when the application starts and are never unloaded during the session.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload