Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 266993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:29:21+00:00 2026-05-11T23:29:21+00:00

I’m writing a prototype to prove the feasibility of something I’m working on. Basically,

  • 0

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.

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:

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

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:29:21+00:00Added an answer on May 11, 2026 at 11:29 pm

    If you read documentation on AppDomainManager you will see a note:

    Do not use AppDomainManager to configure an application domain in ASP.NET. In ASP.NET, configuration must be handled by the host.

    Therefore, you should not use environment variables or registry to customize AppDomainManager.

    I believe you can achieve what you want by simply adding AssemblyResolve event handler to AppDomain.CurrentDomain. I created simple website and it works as expected – dynamic assembly doesn’t get unloaded between page loads.

    protected void Page_Load(object sender, EventArgs e)
    {
       AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve);
       Assembly assembly = Assembly.Load("PhantomAssembly");
       Type t = assembly.GetType("PhantomAssembly.Test");
       MethodInfo m = t.GetMethod("GetIt");
       Response.Write(m.Invoke(null, null));
       t.GetMethod("IncrementIt").Invoke(null, null);
    }
    
    private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
    {
       Assembly asssembly = Assembly.Load(File.ReadAllBytes(@"C:\PhantomAssembly.dll"));
       return asssembly;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.