Why does GetExportedValues ​​<T> () no longer work after using the final .net 4 MEF release?

Over the past few months, I've been developing an extensible infrastructure management app using community preview. I am using the GetExportedValues ​​() method and PartCreationPolicy (CreationPolicy.NonShared) to spoof the factory class (since only the silverlight version supports factory). This works great until I updated the project to use .net 4.0. There is no error, it just doesn't work.

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

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
{
    ....
}

      

+2


a source to share


1 answer


Have you recompiled your extensions for .NET 4.0? If extensions reference the code preview version in MEF, then .NET 4.0 MEF will not pick them up. This is because the export attribute will come from an assembly with a different strong name that .NET 4.0 MEF does not know anything about.



+3


a source







All Articles