Thursday, April 21, 2011 10:37:00 PM

After lots of wasted time trying to figure out why my MEF module in a new WPF application was not loading, I've found that if there is not a constructor that can be used, then there is a silent failure, with no errors.  I had a single constructor in my MEF module which was relying on 2 items to be imported (it is an Importing Constructor). Since one of the items I wanted to import was not created properly by the main application prior to calling this constructor, the constructor was never called.

If you have a MEF module that should load but setting a breakpoint in your constructor reveals that it is never called, then change the module to have a parameterless default constructor and see if that is called. If it is, then you can narrow down which of the Imported parameters in your real constructor is causing the problem.

 

Comments are closed on this post.