I have a Winforms desktop application that loads several parts of MEF with the same type of interface.
Problem: When I try to load more than one type, I get the following exception:
The composition remains unchanged. Changes were rejected due to the following error (s): the composition produced a single compositional error. The main reason is given below. See the CompositionException.Errors property for more information.
1) No reliable export was found that matches the constraint '((exportDefinition.ContractName = "BOCA.TaskPilot.Common.Extensions.IFolderViewExtension") && & (exportDefinition.Metadata.ContainsKey ("ExportTypeIdentity") && "BOCA.TaskPilot. Common.Extensions.IFolderViewExtension ".Equals (exportDefinition.Metadata.get_Item (" ExportTypeIdentity ")))) ', an invalid export may be rejected.
Result: it is not possible to install the import of TaskPilot.Windows.MainForm.FolderViewExtension (ContractName = "BOCA.TaskPilot.Common.Extensions.IFolderViewExtension") 'on the part' TaskPilot.Windows.MainForm '. Element: TaskPilot.Windows.MainForm.FolderViewExtension (ContractName = "BOCA.TaskPilot.Common.Extensions.IFolderViewExtension") → TaskPilot.Windows.MainForm
Here is the code to download the parts:
AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); //string myExecName = Assembly.GetExecutingAssembly().Location; //string myPath = Path.GetDirectoryName(myExecName); catalog.Catalogs.Add(new DirectoryCatalog(@"C:\Data\TaskPilot\Development\Source\BOCA.TaskPilot.FolderView\bin\Debug")); catalog.Catalogs.Add(new DirectoryCatalog(@"C:\Data\TaskPilot\Development\Source\BOCA.TaskPilot.TaskView\bin\Debug")); // Uncomment below line and it works without exceptions raised //catalog.Catalogs.Add(new DirectoryCatalog(@"C:\Data\TaskPilot\Development\Source\BOCA.FileManager\bin\Debug")); var container = new CompositionContainer(catalog); container.ComposeParts(this);
Here is the code in the class for each of the parts of the MEF:
[Export(typeof(IFolderItemsViewExtension)) public partial class TaskTreeView : DevExpress.XtraEditors.XtraUserControl, IFolderItemsViewExtension, IPartImportsSatisfiedNotification]
Here, the Import is used in the Main form:
[ImportMany(AllowRecomposition = true)] private IEnumerable<IFolderItemsViewExtension> TaskViewExtensions = null;
If I uncomment the last line of Catalog.Catalogs.Add, it throws an exception. If I run it without this, everything will be fine. This line loads another user control that implements the IFolderItemsViewExtension interface. I tried just loading a dummy project that all it has is a user control and this interface, and I still get the same exception. No matter what I do, I still get this exception.
Everything seems to be working fine until I load more than one export of the same type of MEF.
The latest version is 2009.22.10.0 System.ComponentModel.Composistion from the MEF download.