views:

120

answers:

1

I have been developing a managed extensibility framework application for the last several months using the community preview. I have been using the GetExportedValues() method and the PartCreationPolicy(CreationPolicy.NonShared) to fake a class factory (since only the silverlight version supports a factory). This was working great until I upgraded the project to use .net 4.0. There is no error, it just doesn't work.

So why did this code stop working? The code follows:

The factory method:

public static IEnumerable<DataActionBase> GetActionsFromDirectory(string PluginsFolder)
{
    IEnumerable<DataActionBase> result = null;

    var catalog = new DirectoryCatalog(PluginsFolder);
    var container = new CompositionContainer(catalog: catalog);

    result = container.GetExportedValues<DataActionBase>();

    return result;
}

Example Export Class:

[Export(typeof(DataActionBase))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class AnAction : DataActionBase
{
    ....
}
+3  A: 

Have you recompiled your extensions against .NET 4.0? If the extensions reference the codeplex preview version of MEF, then the .NET 4.0 MEF won't pick them up. This is because the export attribute would be coming from an assembly with a different strong name, which .NET 4.0 MEF knows nothing about.

Daniel Plaisted
Yes I have recompiled it as a .net 4 assembly. No difference. Also worth noting that using the AssemblyCatalog() produces the same results (passing in the proper assembly of course).
Jason Webb
@BigJason What do you mean by "it doesn't work" then? GetExportedValues() returns an empty list?
Daniel Plaisted
Upon further review you were right. There was a reference to the old mef preview hiding in a dll. Thanks for the help.
Jason Webb