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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:08:20+00:00 2026-06-12T19:08:20+00:00

For my application as described in this question I want to use MEF to

  • 0

For my application as described in this question I want to use MEF to scan the available plugin assemblies and then store all the available import and export information in a serialized format (e.g. a set of strings or a memory stream). This is necessary because I need to transfer the import and export information over an AppDomain boundary without loading the plugin assemblies (essentially I want to delay load the plugins). I found some references, for instance this one or this one but none of the links gave me any idea how to:

  • Extract all the imports and exports from an assembly
  • Serialize all the required import/export information
  • And then later on re-hydrate the serialized information back into imports and exports.

I think I can use the ReflectionModelServices class to create Import/Export definitions but that still leaves the serialization and deserialization parts. Can anybody point me to some examples, documentation or provide me with suggestion as to how to go about these steps?

  • 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-12T19:08:21+00:00Added an answer on June 12, 2026 at 7:08 pm

    This answer to this question was provided by Kevin on the MEF discussion list. It turns out that one can extract all the required information from the MEF ExportDefinition and ImportDefinition data structures with the following code snippets.

    The first step is to load the assembly types into a catalog. Then for each part in the catalog iterate over the import and export definitions. Export definitions can only be placed on types, methods, properties and fields (which my code ignores at the moment). So to process the exports the following code can be used.

    var exports = new List<Tuple<string, MemberInfo>>();
    foreach (var export in part.ExportDefinitions)
    {
        var memberInfo = ReflectionModelServices.GetExportingMember(export);
        Tuple<string, MemberInfo> exportDefinition = null;
        switch (memberInfo.MemberType)
        {
            case MemberTypes.Method:
                exportDefinition = new Tuple<string, MemberInfo>(export.ContractName, memberInfo.GetAccessors().First() as MethodInfo);
                break;
            case MemberTypes.NestedType:
            case MemberTypes.TypeInfo:
                exportDefinition = new Tuple<string, MemberInfo>(export.ContractName, memberInfo.GetAccessors().First() as Type);
                break;
            case MemberTypes.Property:
                // this is a bit ugly because we assume that the underlying methods for a property are named as:
                // get_PROPERTYNAME and set_PROPERTYNAME. In this case we assume that exports always
                // have a get method.
                var getMember = memberInfo.GetAccessors().Where(m => m.Name.Contains("get_")).First();
                var name = getMember.Name.Substring("get_".Length);
                var property = getMember.DeclaringType.GetProperty(name);
                exportDefinition = new Tuple<string, MemberInfo>(export.ContractName, property);
                break;
    
            default:
                throw new NotImplementedException();
        }
    
        exports.Add(exportDefinition);
    }
    

    In order to process the imports, which can only be placed on properties, parameters and fields (which are again ignored) the following code can be used:

    public void ExtractImports()
    {
        var imports = new List<Tuple<string, string>>();
        foreach (var import in part.ImportDefinitions)
        {
            SerializedImportDefinition importDefinition = !ReflectionModelServices.IsImportingParameter(import)
                ? importDefinition = CreatePropertyImport(import)
                : importDefinition = CreateConstructorParameterImport(import);
        }
    }
    
    private Tuple<string, string> CreatePropertyImport(ImportDefinition import)
    {
        var memberInfo = ReflectionModelServices.GetImportingMember(import);
        if (memberInfo.MemberType != MemberTypes.Property)
        {
            throw new ArgumentOutOfRangeException("import");
        }
    
        // this is a bit ugly because we assume that the underlying methods for a property are named as:
        // get_PROPERTYNAME and set_PROPERTYNAME. In this case we assume that imports always
        // have a set method.
        var getMember = memberInfo.GetAccessors().Where(m => m.Name.Contains("set_")).First();
        var name = getMember.Name.Substring("set_".Length);
        var property = getMember.DeclaringType.GetProperty(name);
        return new Tuple<string, string>(import.ContractName, property.ToString());
    }
    
    private Tuple<string, string> CreateConstructorParameterImport(ImportDefinition import)
    {
        var parameterInfo = ReflectionModelServices.GetImportingParameter(import);
        return new Tuple<string, string>(import.ContractName, parameterInfo.Value.ToString());
    }
    

    Note that it seems that imports cannot be provided via method parameters so the code above does not support those.

    Once all the exports and imports have been processed it is a simple question of serializing the stored MemberInfo objects into a string format.

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

Sidebar

Related Questions

i want to develop the blog application which is described in the book ASP.NET
I used the trick described in this question to display a FireMonkey form on
In an application I want to store sensitive data (which can be arbitrarily large)
what I want to accomplish is something like the one described in this this
How do I use OAuth within my Java GWT application? In particular, I want
Question 1 I want to make IPhone application that uses OpenID for authentication. I
I'm trying to implement Application Tests as described here . So far, so good,
As described in the title I would like to develop a Windows Forms Application
I have successfully implemented interop beftween Win32 application and managed .Net dll as described
So, I have an application I'm making that can be simply described as a

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.