AddExportedObject发生了什么?

时间:2015-02-19 16:38:44

标签: mef

我们有很久以前的.NET 2.0源代码,如下所示:

DirectoryCatalog catalog =
    new DirectoryCatalog(Path.Combine(Path.Combine(applicationDirectory, providersDirectory), providerSubdirectory));
CompositionContainer container = new CompositionContainer(catalog);
CompositionBatch batch = new CompositionBatch();
batch.AddPart(this);
batch.AddExportedObject(container);
container.Compose(batch);

多年来一直运行良好,但在将visual studio和框架升级到.NET 4.0之后,MEF似乎不再支持AddExportedObject的调用。

1 个答案:

答案 0 :(得分:0)

您可以阅读here

  

虽然CompositionBatch本身不包含AddExportedObject<T>   有一种扩展方法。扩展方法在   root System.ComponentModel.Composition命名空间,以确保您   包括在你的文件的using语句中。如果你不能得到   扩展方法工作你总是可以直接调用方法   AttributedModelServices

相关问题