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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:34:23+00:00 2026-05-27T05:34:23+00:00

Approach I am employing MEF to create a plugin-nable, if you will, application. My

  • 0

Approach

I am employing MEF to create a plugin-nable, if you will, application. My MEF host has an ILogger which exposes TraceMessage(string message). Class Logger implements ILogger and is decorated with an Export attribute so Logger looks like:

[Export(typeof (ILogger))]
public class Logger : ILogger
{ }

The idea being that the various plugins can be offered a central logger that they can write to. Thus, instantiation would be via [Import] attribue, for example:

[Export(typeof (ILogger))]
public class Logger : ILogger
{
    private readonly IWindsorContainer _container;

    public ICloudTrace CloudTrace
    {
        get { return _container.Resolve<ICloudTrace>(); }
    }

    public Logger()
    {
        _container = new WindsorContainer(new XmlInterpreter());
    }

    public void TraceMessage(string categoryName, string componentName, string message)
    {
        CloudTrace.TraceMessage(categoryName, componentName, message);
    }
}

And subsequently a log message would be written via Logger.TraceMessage(string message).

Problem

However, this approach throws an InvalidOperationException in my host when its trying to resolve exports, with an error message Sequence contains no matching element.

Exports are resolved in ResolveType(string commandType) (where commandType is the command line parameter needed to execute relevant plugin). ResolveType() looks like:

public dynamic ResolveType(string commandType)
{
   try
   {
     return this.Container.GetExports<ICommand, ICommandMetaData>()
                .First(contract => contract.Metadata.CommandType.Equals(commandType, StringComparison.OrdinalIgnoreCase))
                .Value;
    }
    catch (Exception e)
    {
       Console.WriteLine(e.message);
    }
}

I should mention that each plugin has an Execute(Dictionary<string, string> parameters) which is the entry point for the plugin and the class containing this method is decorated with [Export(typeof(ICommand))] [ExportMetadata("CommandType","CommandLine Command string goes here")] attributes.

  • 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-27T05:34:24+00:00Added an answer on May 27, 2026 at 5:34 am

    The problem was in the CompositionContainer construction. Currently, it just loads the plugin assembly specified in the command line instead of doing directory scan or loading currently executing assembly. This has been done for various reasons. So:

    var assemblyCatalog = new AssemblyCatalog(Assembly.LoadFrom(assemblyFile: assemblyToLoad));
    

    where assemblyToLoad is a string to the .dll file for the specific plugin. However, the logger is in the host so the host’s assembly needs to be loaded. Thus:

    var assemblyCatalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()),
                                               new AssemblyCatalog(Assembly.LoadFrom(assemblyFile: assemblyToLoad)));
    

    fixes the issue.
    Thanks to @Matthew Abbott for pointing this out

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

Sidebar

Related Questions

Which approach is better: 1) to use a third-party ORM system or 2) manually
Which approach is better to use if I need a member (sp or func)
What factors determine which approach is more appropriate?
I'm creating a query that will display information for a record which is derived
I inherited a Basic MSI InstallShield ISM to install an application that has a
Which approach is better to use: BoundField.NullDisplayText isn't set. NULL-case is foreseen in SQL
I want to create a C++ cross-platform (Windows and MacOS X) application that sends
Which approach is the better one and why? template<typename T> struct assistant { T
Which approach to displaying popups with jQuery is better? 1) To have a popup
Whats the best approach for writing data to a file that will be picked

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.