Loading multiple assemblies

Dec 17, 2009 at 5:13 PM


I have a question regarding ComposeParts() method.

I have created a catalog directory catalog:

var catalog = new DirectoryCatalog(".");

Current directory contains two DLLs with same exports. They are actually two plug-ins with same type exports.

When I call:

var container = new CompositionContainer(catalog);

I get a 'System.ComponentModel.Composition.ChangeRejectedException'.

Is the reason for this exception the fact that I have two assemblies with the same exports, and MEF cannot map them on imports?




Dec 17, 2009 at 8:06 PM

If you have multiple exports but a single importer of that export, then the parts will get rejected. Can you show code for the parts (exporters / importers) coming into play here?



Dec 18, 2009 at 2:44 AM

What does type where you pass 'this' to ComposeParts look like? Does it have an Export on it?

Dec 18, 2009 at 11:53 AM


That was the problem. When I added:

    [ImportMany(AllowRecomposition = true)]
    public System.Collections.Generic.IEnumerable<IMessageSender> Senders { get; set; }

instead of:

    public IMessageSender MessageSender { get; set; }

it worked.

Thanks a lot!


Yes it does. Using [ImportMeny] instead of [Import] solved a problem.