Import visibility with MEFX

Nov 12, 2012 at 7:57 AM
Edited Nov 12, 2012 at 8:02 AM

I'm trying to match imports and exports with mefx, using /exports and /imports.
I get missing imports in this situation:

Let's demonstrate with the most simple expample ever

namespace Example01
ublic class Program
public class  MyClass
public int MajorRevision { get; set; }

       public class MyExportClass
Export("MajorRevision")] //This one will match.
      public int MajorRevision = 4;

public int MinorRevision = 16;

Running my mefx commands gives these results

mefx /dir:Example01\bin\Debug /parts

mefx /dir:Example01\bin\Debug /exports
MajorRevision : System.Int32
MinorRevision : System.Int32

mefx /dir:Example01\bin\Debug /imports

I get an empty line for "imports". Looking on internet for such problem, I found this article:
But the response doesn't satisfy me. It's sayed "how", but not "why". I'm certainly missing something.

I tried what was explained doing this:

public class MyClass
public int MajorRevision { get; set ; }

Now I get this result with mefx:

mefx /dir:Example01\bin\Debug /imports
MajorRevision : System.Int32.

I would expect this result without the export clause on MyClass. My application is resolving perfectly the parts without this "Export". It's not necessary. Why mefx needs this to see the import? I'm not ready to add unnecessary information in my code just for mefx.

Dec 18, 2012 at 8:44 AM

Hi again,

Nobody can explain this?

Is this behaviour expected?

Thanks for an answer
Olivier Monney

Dec 18, 2012 at 9:18 AM

Hi Oliver,

In MEF's discovery model, only types that have exports are considered "parts". This is because although MEF could find imports on types like the one above, there's no way for a composition container to create instances of them, so instead it ignores them until a method like SatisfyImports() called.

MEFX is only a thin layer over MEF's regular discovery/catalog system, so it maintains the same behaviour. What you're seeing here is expected.

What situation are you aiming to detect, using MEFX in this scenario?

Hope this helps,

Dec 18, 2012 at 1:21 PM


Thanks for your anwser.

The situation I'm aiming to detect is to tell MEFX which classes are initiating a chain composition. In the small example it would be "MyClass"

I just wanted to list my imports and see if any exports were available to satisfy them. But it appears that MEFX would need, as MEF does, to call SatisfyImports() to have the composition begining.
I understand much better how MEFX behaves.