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

MEF weird composition problem.

Feb 23, 2010 at 6:43 PM


here's my problem: I have a bunch of parts discovered by MEF using both a directorycatalog and an assemblycatalog with the current executing directory. It works all fine and dandy on my computer, but when I send my work to others, it only composes the parts in the assemblycatalog.

Now here's what I've checked: I've used the diagnostics DLL included with mefx.exe to dump out a diagnostic log to a file, but on said persons computer, this log only contains information on the parts found in the assembly catalog.

I've also checked after calling ComposeParts that the assemblies that I *want* to compose are indeed found by the directorycatalog. No composition exception is thrown, just a silent failure to compose, and I can't reproduce this problem on my home computer.

I've also checked that the metadata wasn't causing the issue (both by removing the importation of it, and weakly typing it) 

What's weirder is that it used to compose them before for others, but now it does not. It seems pretty hit or miss, with it working for some, but not working for others.


I'm using .NET4, WPF4, and VS2010 all RC1. My compile options are for Any CPU targetting the .NET4 Client Profile. Is there anything i'm missing? Anything which would cause MEF to silently fail to satisfy my imports?



Feb 23, 2010 at 6:52 PM

If the parts are showing up in the catalog but not get created by the container, then it is likely that stable composition is kicking in and rejecting the part, which will not throw an exception. The reason for rejection would be either a required import not being found, or two many implementations being found such as when a shared dll which contains parts is copied in two places.

If you are using MEFX, did you try using the switch to see if parts are being rejected i.e. the /rejected switch?



Feb 23, 2010 at 7:20 PM


i suspected as much, but when using the compositioninfo class in microsoft.componentmodel.composition.diagnostics, and writing the contents of that to an output file, the file did not contain information about the parts I needed. 


however i will try to get my friend to run mefx /dir:./Plugins /verbose /rejected today and see if i get some more information.

thanks for the quick response.

Feb 23, 2010 at 8:08 PM


i just had my friend run mefx with the switches above and nothing came up. am I passing the wrong command line params to mefx.exe? If not, is there anything else I can try



Feb 23, 2010 at 8:27 PM


it gets even weirded. mefx.exe wont list any parts at all in any directory for him? now I'm really scratching my head .. 

Feb 23, 2010 at 10:22 PM

Make sure your version of MEFX is built against the same version of MEF you are using. The .NET 4.0 version of MEFX for example won't work with .NET 3.5 MEF assemblies. You may want to recompile MEFX against your current version of MEF and use that.


Feb 23, 2010 at 10:48 PM
Edited Feb 23, 2010 at 10:52 PM

my project is compiled for the .NET4 Client Profile (RC) and he's using the .NET4 mefx from this website. Should I just checkout the code from Preview9 and compile that code against the .NET4 assemblies? The weird thing is that on my machine mefx works fine, listing the parts, but on his machine it does not. 

I know he's running .NET4 because I gave him the download link myself, and it's my understanding that 3.5SP1 does not even ship with MEF, so I'd think that would error right then and there. That, and WPF4 stuff being included which should crash it as well.

The other weird thing is that MEF used to work on his machine, which is really perplexing to me. However I have another friend with the same issue, so I'll see if I cant try the mefx stuff on him as well.

Thanks for your help thus far!

edit: Just ran it for him with no dice as well. I've verified that the mefx is the one build for .NET4 from codeplex.