开发者

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

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 : Data开发者_Python百科ActionBase
{
    ....
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜