Declaring method exports using Directory Catalog

Mar 29, 2009 at 10:50 PM
I am trying to use a method export in another assembly using the directory catalog.
Apparently MEF doesn't discover the export in the separated assembly, whereas it recognizes the method exports inside the same assembly as the host.
Is this is a known issue?
Developer
Mar 30, 2009 at 5:15 PM
As long as the assembly that you have declared the method export is in the directory catalog this should work. I'm not aware of any know issues around this. If you post enough code to repro perhaps we can help you diagnosis the issue.
Mar 31, 2009 at 11:44 PM
I have for example a console application that contains the following two classes

public class SimpleClass
{
    CompositionContainer container;
            
    [Import("xxx")]
    public IEnumerable<action<string />> XXX { get; set; }
            
    public SimpleClass()
    {
        Compose();
    }

    protected void Compose()
    {
        var catalog = new AggregateCatalog();
        catalog.Catalogs.Add(new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()));
        catalog.Catalogs.Add(new DirectoryCatalog("AddIns"));

        container = new CompositionContainer(catalog);

        var batch = new CompositionBatch();
        batch.AddPart(this);
        container.Compose(batch);            
    }
}

public class AddInA
{        
    [Export("xxx")]
    public void MethodA1(string app)
    {
    }

    [Export("xxx")]
    public void MethodA2(string app)
    {
    }        
}
And in another class library, which is deployed in the AddIns folder, I have the following class

public class AddInB
{
    [Export("xxx")]
    public void MethodB1(string app)
    {
    }        
}
For some reason the collection XXX on SimpleClass contains only 2 items! The one in the AddIns folder is not found/recognized.
I am sure that the class library is investigated by MEF, because it worked for other types of exports.
Developer
Apr 1, 2009 at 7:31 AM
The code looks proper. Just to ensure that the assembly is added to the catalog maybe you can explicitly add an AssemblyCatalog for AddInB. Also did you verify that the 2 functions that exist in the collection are MethodA1 and MethodA2?
Apr 2, 2009 at 9:41 AM
After some investigation, it turned out that the addin dll was not in the right folder, duh!


Apr 3, 2009 at 3:39 AM
This may be a dumb question, but... if you got addinA, with the same export as AddinB, how does the host know which addin it was called on?