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 8900711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:09:52+00:00 2026-06-15T01:09:52+00:00

In my Application_Start I configure Unity using the Unity-AutoRegistration tool: UnityFactory.Configure(config => config .Include(If.ImplementsITypeName,

  • 0

In my Application_Start I configure Unity using the Unity-AutoRegistration tool:

UnityFactory.Configure(config => config
    .Include(If.ImplementsITypeName, Then.Register())
    .ExcludeSystemAssemblies()
);

My UnityFactory class is static. Configure works as follows:

public static void Configure(Func<IAutoRegistration,IAutoRegistration> configuration)
{
    // Store the configuration to be able to apply it again when needed
    UnityFactory.configuration = configuration;

    // Create new UnityContainer
    container = new UnityContainer();

    // Apply configuration
    configuration(container.ConfigureAutoRegistration()).ApplyAutoRegistration();
}

It runs under IIS7 and all works fine when when it’s started.

It stops working whenever the application pool has been recycled. The configuration somehow gets messed up, and it is not able to resolve my classes anymore. However, the static field configuration in the UnityFactory class still contains the configuration as was provided the first time. So the class itself hasn’t changed.

The Application_Start method is not triggered after the application pool has been recycled, so the configuration is not applied again.

If I set a breakpoint and manually apply the configuration again, it all works again.

What is happening here? Why is Unity forgetting about all my classes? And is there an event I can subscribe to which allows me to know when the pool has been recycled?

  • 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-06-15T01:09:53+00:00Added an answer on June 15, 2026 at 1:09 am

    Apparantly, when the application pool is recycled, the assemblies are released, which causes Unity to be unable to find any declared classes within them.

    I’ve managed to solve this effect by specifically loading the assemblies for Unity. This way, they remain in memory, even when the application pool is recycled.

    public static void Configure(Func<IAutoRegistration,IAutoRegistration> configuration)
    {
        // Create new UnityContainer with auto registration
        container = new UnityContainer();
        var autoRegistration = container.ConfigureAutoRegistration();
    
        // Load assemblies
        var path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "bin");
        foreach (string dll in Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories))
        {
            autoRegistration.LoadAssemblyFrom(dll);
        }
    
        // Apply configuration
        configuration(autoRegistration).ApplyAutoRegistration();
    }
    

    And to answer my questions:

    What is happening here? Why is Unity forgetting about all my classes?

    When the application pool recycles, assemblies may be released from memory. When they are required again, they are re-loaded. However, as they seem to come from different files, Unity is not able to know that they are in fact actually the same assemblies as before, and thus can’t find the original class definitions.

    And is there an event I can subscribe to which allows me to know when the pool has been recycled?

    Apparantly, there is no such thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to handle the application_start event without using the global.asax? The
I have seen at least two ways to include an external log4net config file
So, I have log4net configuration in log4net.config file and I don't want to include
I'm using the Unity MVC3 code at http://unitymvc3.codeplex.com/ to have a NHibernate session per
Using NHibernate, I need to be able to configure my application to sort a
This is how my Application_Start looks: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); _container.Register(Component.For<IWindsorContainer>()
I use Log4Net for logging. When the application starts, I call log4net.Config.XmlConfigurator.Configure(); But this
I have a WCF service configured and I'm using routing to configure it. Everything
On application start I'm creating Config object (Singleton). How could I make Config object
How to call or make the javascript function from the Application_Start of global.asax in

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.