ImportCardinalityMismatchException Shell MEF Silverlight

Nov 5, 2011 at 11:35 PM

Hi all,

This is my first post here though I've been using forums such as this for a while. So Thanks for all your help thus far! However, although there's a lot on t'interweb about this problem, I still can't seem to "get it". I'm starting out with Silverlight/Prism/MEF... And have built some test apps to get the hang of each part before putting it all together.... So far so good... but now I've hit a brick wall. I have other apps that load the shell just fine, but I'd like to know why it isn't working in this case : The Bootstrapper etc looks exactly (as far as I can see) as the Modularity for MEF Quickstart. I've got other modules that load from the ModulesCatalog.xaml. Finds them just fine. If I put a breakpoint in where I load the shell, I can see that the container has the shell in it, though I STILL get the ImportCardialityMismatchException. I've tried"everything" before coming here to plead for your infinite wisdom.

Here's the meat (simplified):



BOOTSTRAPPER:

 [CLSCompliant(false)] public class Bootstrapper : MefBootstrapper { private readonly CallbackLogger callbackLogger = new CallbackLogger(); protected override void InitializeShell() { base.InitializeShell(); Application.Current.RootVisual = (UIElement) this.Shell; } protected override DependencyObject CreateShell() { var theShell = this.Container.GetExportedValue<Shell>(); return theShell; } protected override ILoggerFacade CreateLogger() { return this.callbackLogger; } protected override void ConfigureAggregateCatalog() { base.ConfigureAggregateCatalog(); this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly)); } protected override void ConfigureContainer() { base.ConfigureContainer(); this.Container.ComposeExportedValue<CallbackLogger>(this.callbackLogger); } protected override IModuleCatalog CreateModuleCatalog() { Uri modules = new Uri("/Silverlight_RIA_App_V2;component/ModulesCatalog.xaml", UriKind.Relative); var catalog = Modularity.ModuleCatalog.CreateFromXaml(modules); return catalog; } } }
THE SHELL:
[Export]
    public partial class Shell : UserControl , IPartImportsSatisfiedNotification
    {
        [Import(AllowRecomposition = false)]
        public IModuleTracker moduleTracker;

        [Import(AllowRecomposition = false)]
        public IModuleManager moduleManager;

        [Import(AllowRecomposition = false)]
        public CallbackLogger Logger;



        public Shell()
        {
            InitializeComponent();
        }

        public void Log(string message, Category category, Priority priority)
        {
            //this.tbInfo.Text = string.Format(CultureInfo.CurrentUICulture, "[{0}][{1}] {2}\r\n", category, priority, message);
        }

        private void View_Loaded(object sender, System.Windows.RoutedEventArgs e)
        { 
        }
        public void OnImportsSatisfied()
        {
            this.DataContext = this.moduleTracker;

            this.Logger.Callback = this.Log;
            this.Logger.ReplaySavedLogs();

            this.moduleManager.ModuleDownloadProgressChanged += this.ModuleManager_ModuleDownloadProgressChanged;
            this.moduleManager.LoadModuleCompleted += this.ModuleManager_LoadModuleCompleted;

        }

        private void ModuleManager_ModuleDownloadProgressChanged(object sender, ModuleDownloadProgressChangedEventArgs e)
        {
            this.moduleTracker.RecordModuleDownloading(e.ModuleInfo.ModuleName, e.BytesReceived, e.TotalBytesToReceive);
        }
       
        private void ModuleManager_LoadModuleCompleted(object sender, LoadModuleCompletedEventArgs e)
        {
            this.moduleTracker.RecordModuleLoaded(e.ModuleInfo.ModuleName);
        }

    }
}



THANKS!!!