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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:45:34+00:00 2026-06-18T03:45:34+00:00

Background: I’m interested in using MEF to provide a plug-in architecture in a WinForm

  • 0

Background:

I’m interested in using MEF to provide a plug-in architecture in a WinForm application using C# with .NET 4.0, but I am not clear on a couple of things.

First: I have not worked at all with building DLLs yet in C#, and I’m a little fuzzy on the concept of DLL Assemblies and how a DLL is normally loaded into memory ( meaning, all at once or in pieces as needed )

Intent:

The program will be a machine hardware control framework, and will be made up of a primary WinForm GUI that is a generic environment with basic toolbars, menus, etc – but no bulk GUI content. ( Think: MDI Parent but not actually ).

The plug-ins provide all of the controls for a specific machine. Each of many possible plug-ins will contain potentially 30 to 50 large UserControls, each populated with many dozens of WinForm Controls and tons of support code that makes up the various machine control panels.

This means that the main program is a lightweight general framework and the plug-ins contain the bulk of the GUI controls and functionality that will be shown in the main program user interface, including lots of icons, images, and other resources. This will make the plug-in DLLs potentially quite large.

The goal is to allow the user to select a plug-in from a menu, and then upon selection, load and run the plug-in which will then fill the mostly empty main GUI with panels, menus, and toolboxes galore.

To do this, I need to first extract metadata from each plug-in to populate the initial menu for the program, which will include the plug-in title, description, icon, version numbers, and other bits of info.

Here are the questions:

With MEF, if I try to read the metadata from each of many large DLLs that are stored in a plug-in folder, will the entire DLL be copied into memory before the metadata values are accessed ?

If so, is there any way to open each DLL file and only read the metadata into memory to build the initial menu – then later load the full selected DLL through MEF ?

I am assuming that the typical DirectoryCatalog and AggregateCatalog template for reading plugins through MEF will copy all of the discovered DLLs into memory and store them in the catalog collection.

Do DLLs contain one contiguous code block ( assembly ), or can they contain multiple separate blocks that are indexed and copied to memory individually as needed ( multiple assemblies ) ?

I’m probably not understanding the fundamentals, and maybe confusing terms. I would appreciate any insight into the load behavior of MEF, DLLs, and Assemblies in general. Thanks !

  • 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-18T03:45:35+00:00Added an answer on June 18, 2026 at 3:45 am

    With MEF, if I try to read the metadata from each of many large DLLs
    that are stored in a plug-in folder, will the entire DLL be copied
    into memory before the metadata values are accessed ?

    As far as I know the entire DLL will be loaded into memory. This does not have anything to do with MEF though. DirectoryCatalog will load the assembly (through AssemblyCatalog) using a call to Assembly.Load. This method is not part of MEF but it is a core method of the .NET Framework. Most of the loaded assemblies are loaded this way. If you monitor the process running your application using Process Explorer you can see that the Virtual Size will be increased by the size of the loaded assembly. So if you load huge assemblies the Virtual Size of your process will be high.

    If so, is there any way to open each DLL file and only read the
    metadata into memory to build the initial menu – then later load the
    full selected DLL through MEF ?

    There are ways to do this.

    One way is to create a new application domain, create the CompositionContainer in the new AppDomain and check the discovered parts. Then serialize information about these parts to the main AppDomain. Finally unload the new AppDomain. Then you can check which parts you really need and only load the assemblies that contain them. An example on how to do this can be found in this answer.

    Another approach is to use Mono.Cecil. This is great library that helps you inspect assemblies without loading them. You can combine it with MEF’s Export Metadata in a method like this:

    public static bool IncludesTypeWithSpecificExportMetadata<T>(string assemblyPath, string name, T value)
        {
            AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath);
    
            bool typeWasFound = false;          
    
            foreach (TypeDefinition typeDefinition in assemblyDefinition.MainModule.GetTypes())
            {
                foreach (CustomAttribute customAttribute in typeDefinition.CustomAttributes)
                {
                    if (customAttribute.AttributeType.FullName == typeof(ExportMetadataAttribute).FullName)
                    {
                        string actualName = (string)customAttribute.ConstructorArguments[0].Value;
                        T actualValue = (T)((CustomAttributeArgument)customAttribute.ConstructorArguments[1].Value).Value;
                        if (actualName.Equals(name) && actualValue.Equals(value))                        
                        {
                            typeWasFound = true;                       
                        }
                    }
                }
            }
    
            return typeWasFound;
        }
    

    Given an assembly file path and a name/value pair this method will inspect the assembly using Mono.Cecil and look for types decorated with the ExportMetadataAttribute and with the same name/value pair.

    I am assuming that the typical DirectoryCatalog and AggregateCatalog
    template for reading plugins through MEF will copy all of the
    discovered DLLs into memory and store them in the catalog collection.

    True.

    Do DLLs contain one contiguous code block ( assembly ), or can they
    contain multiple separate blocks that are indexed and copied to memory
    individually as needed ( multiple assemblies ) ?

    I don’t know about this. You might find the answer in “Essential .NET Volume 1” by Don Box or “C# via CLR” by Jeffrey Richter.

    I’m probably not understanding the fundamentals, and maybe confusing
    terms. I would appreciate any insight into the load behavior of MEF,
    DLLs, and Assemblies in general. Thanks !

    The books I mentioned above include in detail how assemblies are resolved/loaded blah blah. Also have a look at Suzanne Cook’s blog.

    Now I would like to ask you something. Do you really need to embed large files to your assemblies? If you can find another way then you will not need any of this. Your plug-in engine will be a little bit simple.

    Finally I would suggest to have a look at Microsoft’s Smart Client Software Factory. It can do pretty much everything you mention and more. It will take some effort to understand it and feel comfortable with it but in the long run it will probably save you loads of time.

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

Sidebar

Related Questions

BackGround : I have developed a SenchaTouch application using sencha 2.1. Now I am
Background: This is a request for something that may not exist yet, but I've
Background We're using System Center 2012 to deploy a Windows 8 Metro-style application to
Background: I'm in the process of creating a web service using ASP.NET 2.0. This
Background: I am using HtmlAgilityPack (.Net), so I'm forced to use XPath 1.0, which
Background : I have a .Net 3.5 WPF Prism-based application running on Windows XP
Background: our web services are company internal, but with a lot different systems using
Background: We're building an application that allows our customers to supply data in a
Background: I'm using the (fantastic) Vim plugin python-mode , which includes the pep8 linter.
Background - I am using paramiko to put files on a bunch of remote

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.