我從網上得到一個簡單的示例,使用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