Import Cardinality Mismatch Exception

Jan 10, 2011 at 5:08 AM

I am learning MEF and trying to do a proof of concept WPF app modeled after the MVVM pattern

the CreateShell method is giving me following Import Cardinality Mismatch Exception.  This is very frustrating any help would be appreciated.

No valid exports were found that match the constraint '((exportDefinition.ContractName == "AppName.Shell") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "AppName.Shell".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))', invalid exports may have been rejected.

 

MEF Bootstrapper has the following code:

 protected override void ConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();

     this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Shell).Assembly));
     this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(BaseNotifyPropertyChanged).Assembly));
}
 protected override DependencyObject CreateShell()
{
return this.Container.GetExportedValue<Shell>();
}
 
protected override void InitializeShell()
{
base.InitializeShell();

    IRegionManager regionManager = this.Container.GetExportedValue<IRegionManager>();
    regionManager.AddToRegion(RegionNames.XamRibbonRegion, typeof(XamRibbonRegionAdapter));
    regionManager.AddToRegion(RegionNames.DockingAreaRegion, typeof(XamDockManagerRegionAdapter));
    regionManager.AddToRegion(RegionNames.OutlookBarRegion, typeof(XamOutlookBarRegionAdapter));
    regionManager.AddToRegion(RegionNames.SystemMessagesRegion, typeof(ucSystemMessagesRegionAdapter));   

    Application.Current.MainWindow = (Shell)this.Shell;
    Application.Current.MainWindow.Show();

protected override RegionAdapterMappings ConfigureRegionAdapterMappings() 
{
    RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
   mappings.RegisterMapping(typeof(XamRibbon), Container.GetExportedValue<XamRibbonRegionAdapter>());
    mappings.RegisterMapping(typeof(XamDockManager), Container.GetExportedValue<XamDockManagerRegionAdapter>());
    mappings.RegisterMapping(typeof(XamOutlookBar), Container.GetExportedValue<XamOutlookBarRegionAdapter>());
    mappings.RegisterMapping(typeof(ucSystemMessages), Container.GetExportedValue<ucSystemMessagesRegionAdapter>());
    return mappings;
}
May 12, 2011 at 9:29 AM
Edited May 12, 2011 at 9:29 AM

 

Make sure that your Shell is exported:

<Export()>
Partial Public Class Shell ... 
Hope this solves your problem, Dragos