none
MEF Import problem RRS feed

  • Question

  • I have used MEF with Prism before without issues. Now I try the simplest "stand-alone" MEF and I get problems.

    I have 2 assemblies, one of them is a wpf application, the other is a lib (dll).

    In the lib assembly one class (public, non-static) is named ExportedType and attributed with Export.
    [Export]
    public class ExportedType {... parameterless constructor here};

    In the wpf assembly one class (the main window) has a field which is of the same type as the exported type mentioned above and is attributed with Import.
    [Import]
    public ExportedType exportedType;

    In the wpf app OnStartup() method I set up the compositions as follows:
    AssemblyCatalog catalogWithExports = new AssemblyCatalog(typeof(ExportedType).Assembly);
    CompositionContainer container = new CompositionContainer(catalogWithExports);

    But the exportedType field in the wpf assembly is always null (I am not trying to access it from the constructor of the main window).

    What is the basics not working here ?
    (output window does not give any clue, other tools available ?)

    Sunday, May 10, 2015 7:03 AM

Answers

  • Sorry for disturbing.Think I found out my self, even if the sample does not show any container.ComposeParts(this) I tried it with no success, but that was because it wasn't the Application which had dependency, but the MainWindow.
    Changed and working.
    Sunday, May 10, 2015 7:13 PM

All replies

  • Sorry for disturbing.Think I found out my self, even if the sample does not show any container.ComposeParts(this) I tried it with no success, but that was because it wasn't the Application which had dependency, but the MainWindow.
    Changed and working.
    Sunday, May 10, 2015 7:13 PM
  • Hello EuroEager,

    I'm glad to hear that you got it working and Thank you for sharing your solutions & experience here. It twill be very beneficial for other community members who have similar questions.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 11, 2015 1:53 AM
    Moderator