tags:

views:

19

answers:

1

I'm learning MEF and have some problems with understanding it. I have small project with MainWindow and some assemblies which are loaded into catalog. One of the assemblies need to show a view from other assembly, once at a start and later, if I click the button. Here is the head part of this view:

[Export("OperatingPlugin", typeof(UserControl))]    
[ExportMetadata("Name", "EDIFACT Viewer")]
[ExportMetadata("Dock", "main")]
[ExportMetadata("Hidden",true)]
[ExportMetadata("Icon","editedi.xaml")]
public partial class EdiView : UserControl
{
    //[Import("PluginSelectFile", typeof(UserControl))]
    //public Lazy<UserControl> SelectFile { get; set; }

When the view loads, I want to show another view (in separate assembly) which selects a file. I can see in catalog in app.xaml.cs all views (also PluginSelectFile), but after the comments above are removed this assembly (EDIFACT Viewer) is no more showing. Where I am something missing?

A: 

Most likely the export of PluginSelectFile doesn't match the import when uncommented, or there are multiple matching exports, both of which would cause the OperatingPlugin export to be rejected.

See my blog post on How to Debug and Diagnose MEF Failures for details on why this happens and how you can figure out how to fix it.

Daniel Plaisted
Yes, import and export names were not matching - found during debugging.
Gabriel