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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:52:29+00:00 2026-06-17T15:52:29+00:00

My application is comprised of a few core assemblies and several extension/plugin assemblies. In

  • 0

My application is comprised of a few core assemblies and several extension/plugin assemblies. In order for MEF to know all the parts the plugins have to offer, I have to load these assemblies even if I’m never going to use any of their parts. This makes the application take more time to start (if I’m going to load all the assemblies on startup) and also increases the memory footprint.

Ideally, I won’t have to load the assemblies until I actually need them. I would load only the plugins’ export data, and when I actually need to import a part, MEF would load the assembly and provide the part.

I found that there is something that does pretty much everything I just wrote, but after asking about it in MEF CachedAssemblyCatalog – Lazy Loading of Assemblies, I realized this code isn’t considered stable and is not being maintained by the MEF team, so I’ve decided not to use it.

My question is how then can I achieve this behavior:

  • Being able to access plugin assemblies’ export metadata without loading their entire assembly.
  • Transparent integration with the code importing the parts; i.e. use imports as usual – someone else (a specialized catalog?) will take care of loading the assemblies if necessary and provide the requested part.
  • Not losing any existing MEF functionality such as recomposition, lazy types, etc.

I’m completely fine with a solution that requires parsing the plugins in advance to create a metadata assembly, XML file or whatnot.

  • 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-17T15:52:30+00:00Added an answer on June 17, 2026 at 3:52 pm

    If you are just after delay loading the assemblies then you could potentially use part of the solutions to this question. You wouldn’t need to grab all the information that is retrieved in that solution. Probably only the contract name, assembly name and whether the part is exporting or importing the contract. Then you can write a catalog that loads the assemblies as you need them, for instance like this:

    public sealed class DelayLoadingCatalog : ComposablePartCatalog
    {
        // List containing tuples which have the 'contract name' 
        // and the 'assembly name'
        private readonly List<Tuple<string, string>> m_Plugins 
            = new List<Tuple<string, string>>();
        private readonly Dictionary<string, AssemblyCatalog> m_Catalogs 
            = new Dictionary<string, AssemblyCatalog>();
    
        public DelayLoadingCatalog(IEnumerable<Tuple<string, string>> plugins)
        {
            m_Plugins.AddRange(plugins);
        }
    
        public override IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
        {
            var partsToLoad = m_Plugins
                .Where(t => t.Item1.Equals(definition.ContractName));
            foreach (var part in partsToLoad)
            {
                if (!m_Catalogs.ContainsKey(part.Item2.Name))
                {
                    var assembly = Assembly.Load(new AssemblyName(part.Item2.Name));
                    m_Catalogs.Add(part.Item2.Name, new AssemblyCatalog(assembly));
                }
            }
    
            return m_Catalogs.SelectMany(p => p.Value.GetExports(definition));
        }
    
        public override IQueryable<ComposablePartDefinition> Parts
        {
            get 
            { 
                throw new NotImplementedException(); 
            }
        }
    }
    

    which you can then use like this

    class Program
    {
        public void Init()
        {
            var domainSetup = new AppDomainSetup
            {
                ApplicationBase = Directory.GetCurrentDirectory(),
            };
    
            var scanDomain = AppDomain.CreateDomain(
                "scanDomain", 
                null, 
                domainSetup);
            var scanner = scanDomain.CreateInstanceAndUnwrap(
                typeof(MyScanner).Assembly.FullName, 
                typeof(MyScanner).FullName) as MyScanner;
            var plugins = scanner.Scan(myPluginsPath);
    
            // Make sure we don't have the assemblies loaded anymore ...
            AppDomain.Unload(scanDomain);
    
            var catalog = new DelayLoadingCatalog(plugins);
            var container = new CompositionContainer(catalog);
    
            container.ComposeParts(this);
        }
    
        [Import("MyCoolExport")]
        public object MyImport
        {
            get;
            set;
        }
    }
    

    The example DelayLoadCatalog isn’t very smart as it will keep searching through the list of Tuples. Optimizing the code shouldn’t be too hard though. For example you could however check if all assemblies have been loaded and stop searching through that list at that point.

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

Sidebar

Related Questions

My application may have strings comprised of different alphabets / languages in a single
In my application, I have created a CALayer (with a few sublayers - the
My application is composed from quite a few assemblies (plug-ins) that are loaded by
We have a system which is composed of few applications. Each application at certain
I was building a java desktop application from few days and all was going
We have a few projects that involve building an application that is composed of
I have some graphical oriented Windows-Store-App application that logically composed from few layers. Each
I have an application composed of a main view and a secondary view which
I have a .NET windows forms application compiled as x86 – it needs to
here is a good question: I have an application compiled for iPhone OS 2.21.

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.