This project has moved and is read-only. For the latest updates, please go here.

New to MEF. Need a second set of eyes please.

Feb 1, 2011 at 2:51 PM


I stumbled on to MEF while attempting to learn the MVVM pattern.  I downloaded the WpfApplicationFramework project and thought I was on my way.  What I didnt bank on was the usage of the System.ComponentModel Library.  I love the concepts and the purity of the techniques used.  However, while I'm a believer at this point I am having a devil of a time getting passed the initialize sequence.  Im getting the famous error "ImportCardinalityMismatchException"   I have learned quit a bit through my troubleshooting but not enough to overcome it I'm afraid.  I have been at this for a few weeks and am getting frustrated.  I have changed my code several different ways, downloaded a cool little MEF debugger, and tried my own ways to make it work.  I think a second set of eyes are needed at this point.

 I am following the Book Library example in the WpfApplicationFramework to create my own project.  I would love to get my project working using MEF.  The good news is I get MVVM now lol!  :)

Im not asking anyone to write my code for me, but rather to take a look at my code to see what I am missing.  Please respond to this post and I will zip up my code for your review.  Sorry Its a bit to lengthy to cut and paste in a post.


Thank you so much for any assistance in helping me get my head around MEF



Feb 3, 2011 at 7:16 AM

I'm not familiar with the WpfApplicationFramework or the source code but I do know when and how an ImportCardinalityMismatchException might occur.

Do you think you could post some of the code which you think is the problem or do you want me to explain how the ImportCardinalityMismatchException might occur?

Feb 3, 2011 at 1:58 PM

Thank you for your response.  I actually figured out the issue yesterday.  I was working on something else and happened to glance at the error and read it in a different frame of mind.  It actually made perfect sense.  There was a mismatch because one of my interfaces hadnt been inherited by a class.  hence mismatch!  :)

For those of you learning MEF.  This is a great set of libraries.  Its clean and pure once you get everything set up correctly.  Remember you use interfaces to communicate amongst your classes BUT you must use all that you've setup for export.  The exceptions that are thrown are pretty easy to read once you understand what they mean.

I hope this helps someone.  I struggled with it for 2 weeks!  :)