locked
No valid exports were found that match the constraint Error RRS feed

  • Question

  • Hi,

    I am getting a strange error when importing a ChildWindow in my shell.xaml.cs. Could someone please shed some light on how to fix this?

    Please find full code and error message below.

    I import the ChildWindow using this attribute:

     [Import]
      public ChildWindow PlugInPopup { get; set; }

    I export the ChildWindow like this:

    [Export(typeof(ChildWindow))]
     public partial class NotesView : ChildWindow

    The error is thrown here:

    deployment.DownloadCompleted += (s, e2) =>
                    {
                        CompositionInitializer.SatisfyImports(this);
                        ShowPopup();
                    };

    This is the error I get:

    {System.ComponentModel.Composition.ChangeRejectedException: 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) No valid exports were found that match the constraint '((exportDefinition.ContractName == "System.Windows.Controls.ChildWindow") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "System.Windows.Controls.ChildWindow".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))', invalid exports may have been rejected.

    Resulting in: Cannot set import 'PrismBreakStart.View.Shell.PlugInPopup (ContractName="System.Windows.Controls.ChildWindow")' on part 'PrismBreakStart.View.Shell'.
    Element: PrismBreakStart.View.Shell.PlugInPopup (ContractName="System.Windows.Controls.ChildWindow") -->  PrismBreakStart.View.Shell

       at System.ComponentModel.Composition.CompositionResult.ThrowOnErrors(AtomicComposition atomicComposition)
       at System.ComponentModel.Composition.Hosting.ComposablePartExportProvider.Compose(CompositionBatch batch)
       at System.ComponentModel.Composition.Hosting.CompositionContainer.Compose(CompositionBatch batch)
       at System.ComponentModel.Composition.CompositionInitializer.SatisfyImports(ComposablePart part)
       at System.ComponentModel.Composition.CompositionInitializer.SatisfyImports(Object attributedPart)
       at PrismBreakStart.View.Shell.<button1_Click>b__0(Object s, AsyncCompletedEventArgs e2)
       at System.ComponentModel.Composition.Hosting.DeploymentCatalog.OnDownloadCompleted(AsyncCompletedEventArgs e)
       at System.ComponentModel.Composition.Hosting.DeploymentCatalog.HandleOpenReadCompleted(Object sender, OpenReadCompletedEventArgs e)
       at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
       at System.Net.WebClient.OpenReadOperationCompleted(Object arg)}

    Full code

    Shell.xaml.cs Code
    --------------------------

     public partial class Shell : UserControl
        {
           
            public Shell(ShellViewModel viewModel )
            {
                InitializeComponent();
                this.DataContext = viewModel;
            }

            [Import]
            public ChildWindow PlugInPopup { get; set; }
            
            bool plugInsInitialized = false;

            private void button1_Click(object sender, RoutedEventArgs e)
            {
                if (!plugInsInitialized)
                {
                    plugInsInitialized = true;
                    var deployment = new DeploymentCatalog("NotesModule.xap");
                    deployment.DownloadCompleted += (s, e2) =>
                    {
                        CompositionInitializer.SatisfyImports(this);
                        ShowPopup();
                    };
                    CompositionHost.Initialize(new DeploymentCatalog(), deployment);
                    deployment.DownloadAsync();
                }
                else
                    ShowPopup();
            }

            private void ShowPopup()
            {
                if (PlugInPopup != null)
                    PlugInPopup.Show();
            }
        }

    NotesView.xaml.cs ChildWindow
    -----------------------------------------

     [Export(typeof(ChildWindow))]
        public partial class NotesView : ChildWindow
        {
            public NotesView()
            {
                InitializeComponent();
                _Context = new NotesDomainContext();
               
                noteDataGrid.ItemsSource = _Context.Notes;
               
                if (!DesignerProperties.IsInDesignTool)
                {
                    _Context.Load(_Context.GetNotesQuery(), loadOp =>
                    {
                        if (loadOp.HasError)
                        {
                            MessageBox.Show("Error loading notes: " + loadOp.Error.Message);
                            loadOp.MarkErrorAsHandled();
                        }
                    }, null);
                }
            }
            NotesDomainContext _Context;


            private void OKButton_Click(object sender, RoutedEventArgs e)
            {
                _Context.SubmitChanges(submitOp =>
                {
                    if (submitOp.HasError)
                    {
                        MessageBox.Show("Error loading notes: " + submitOp.Error.Message);
                        submitOp.MarkErrorAsHandled();
                    }
                }, null);
                this.DialogResult = true;
            }

            private void CancelButton_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = false;
            }

            private void noteDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
            {

                if (e.HasError)
                {
                    System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                    e.MarkErrorAsHandled();
                }
            }

            private void button1_Click(object sender, RoutedEventArgs e)
            {
                AddNoteView addNote = new AddNoteView(_Context);
                addNote.Show();
            }
        }

     

    AddNoteView.xaml.cs ChildWindow
    --------------------------------------------

     public partial class AddNoteView : ChildWindow
        {
            NotesDomainContext _Context;
            public AddNoteView(NotesDomainContext context)
            {
                InitializeComponent();
                _Context = context;
            }

            private void OKButton_Click(object sender, RoutedEventArgs e)
            {
                //_Context.Notes.Add(new Data.Note { Content = textBox1.Text });
                _Context.Notes.Add(new Note { Content = textBox1.Text });
                this.DialogResult = true;
            }

            private void CancelButton_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = false;
            }
        }

     

     

    Friday, February 25, 2011 3:35 AM

All replies

  • Hi,

    Could someone shed some light please?

    Sunday, February 27, 2011 1:16 PM
  • Hi Pallone,

    What I can imagine goes wrong in your code is this:

    - you have a rather general class "childwindow" that is implemented by your NotesView.

    It seems to me that there could be more Modules that implement the "childwindow". If you do not distinguish between them by adding some identification in the metadata, then MEF will not be able to construct a solid "hierarchy", so refuses to construct one at all.

    For a further explanation on this and on how to add MetaData identifiers, look at this video.

    Good luck

    Peter

    Sunday, March 27, 2011 5:54 AM
  • can imagine if you change your import to [Import(typeof(ChildWindow))]  or remove the typeof from the export it'll work?

     

    Monday, April 18, 2011 12:17 PM
  • Hi,

     [Import(typeof(ChildWindow))]
      public ChildWindow PlugInPopup { get; set; }

    I export the ChildWindow like this:

    [Export(typeof(ChildWindow))]
     public partial class NotesView : ChildWindow

    That seems you are duplicate container. How about you issue.

    Wednesday, April 27, 2011 12:24 PM