No valid export were found

Topics: Prism v4 - Silverlight 4
Mar 16, 2011 at 8:54 PM

Good morning,

I have this error and I cannot find the solution... :

"No valid exports were found that match the constraint '((exportDefinition.ContractName == \"Learning.Prism.Shell\") AndAlso (exportDefinition.Metadata.ContainsKey(\"ExportTypeIdentity\") AndAlso \"Learning.Prism.Shell\".Equals(exportDefinition.Metadata.get_Item(\"ExportTypeIdentity\"))))', invalid exports may have been rejected."
Here is my Shell.xaml.cs
    public partial class Shell : UserControl, IPartImportsSatisfiedNotification
        private const string _moduleAName = "ModuleA";
        private static Uri _moduleAViewUri = new Uri("/ModuleAView", UriKind.Relative);

       // [Import(AllowRecomposition = false)]
       // public IModuleManager ModuleManager;

        [Import(AllowRecomposition = false)]
        public IRegionManager RegionManager { get; private set; }

        public Shell()

        public void OnImportsSatisfied()
            //this.ModuleManager.LoadModuleCompleted += 
            //    (s, e) =>
            //    {
            //        if (e.ModuleInfo.ModuleName == _moduleAName)
            //            this.RegionManager.RequestNavigate(RegionNames.MainContentRegion, _moduleAViewUri);
            //    };
And my bootstrapper 
public class BootStrapper : MefBootstrapper
        //protected override void ConfigureAggregateCatalog()
        //    base.ConfigureAggregateCatalog();

        //    this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(BootStrapper).Assembly));

        protected override System.Windows.DependencyObject CreateShell()
            return this.Container.GetExportedValue<Shell>();

        protected override void InitializeShell()
            Application.Current.RootVisual = (UIElement)this.Shell;
And my Application_Stratutp @ App.xaml.cs
private void Application_Startup(object sender, StartupEventArgs e)
            BootStrapper bootStrapper = new BootStrapper();
Thank you for your help,
Mar 16, 2011 at 8:57 PM


The problem you're experiencing could be because you're not adding you'r Bootstrapper's Assembly Catalog to the Aggregate Catalog, hence the Shell isn't correctly exported.

You could try uncommenting the ConfigureAggregateCatalog method override in your Bootstrapper class.

I hope you find this helpful.

Guido Leandro Maliandi

Mar 16, 2011 at 9:43 PM

Thank you Guido. It works but I have another error ;)

"Échec de la tentative d'accès de la méthode 'Microsoft.Internal.ReflectionInvoke.SafeInvoke(System.Reflection.MethodInfo, System.Object, System.Object[])' à la méthode 'Learning.Prism.Shell.set_RegionManager(Microsoft.Practices.Prism.Regions.IRegionManager)'."

I cannot access the method MicrosofT.INternal.ReflectionInvoke.SaveInvoke();

Do you have an idea why ?



Mar 16, 2011 at 10:12 PM

I found the solution.

I was importing on a read only property.

The good solution is :

[Import(AllowRecomposition = false)]
        public IRegionManager RegionManager;

//Instead of
[Import(AllowRecomposition = false)]
        public IRegionManager RegionManager { get; private set;}
Mar 17, 2011 at 3:29 PM


I'm glad that you've found a solution to your problem. Thank you for sharing it with the rest of the community, as other users facing similar problems might benefit from reading that.

Guido Leandro Maliandi