我从网上得到一个简单的示例,使用System.ComponentModel.Composition.dll版本工作在.NET 3.5框架精细V2.0.50727MEF - 迁移从.NET 3.5到.NET 4.0
我已经更改了项目定义并将目标更改为.NET 4.0,并且它工作得很完美。
当我替换上面的.dll文件的V2.0.50727版本是v4.0.30319我得到的容器的组成过程中抱怨错误的最新版本。它打破了代码如下:
private void LoadPlugins() {
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog);
container.ExportsChanging += new EventHandler(container_ExportsChanging);
var batch = new CompositionBatch();
batch.AddPart(this);
container.Compose(batch); // throws Exception
}
而例外的是以下内容:
System.ComponentModel.Composition.ChangeRejectedException was unhandled
Message=The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) More than one export was found that matches the constraint '((exportDefinition.ContractName == "MefTutorial.IPlugin") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "MefTutorial.IPlugin".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.
Resulting in: Cannot set import 'MefTutorial.PluginConsumer._myPlugins (ContractName="MefTutorial.IPlugin")' on part 'MefTutorial.PluginConsumer'.
Element: MefTutorial.PluginConsumer._myPlugins (ContractName="MefTutorial.IPlugin") --> MefTutorial.PluginConsumer
什么我需要做的迁移到.NET 4.0关于MEF?
我会继续这个。 Visual Studio的“清洁”是垃圾。它让我有一天在追逐类似的错误。只是当我检查输出文件夹时,我意识到它仍然充满了旧文件... – Tim 2011-02-17 11:48:16
是的,我也遇到了这个问题,还有MEF。它仍然发现老dll并抱怨。 – Femaref 2011-02-17 12:54:57