Help required regarding RemoveParts

May 18, 2009 at 7:05 AM

hi there.

i am currently working with MEF and facing some problems

what i want is to load dlls from the directory.

first i scan the directory and save two things in dictionary

Name property from respective DLL (as string)

and Module Name (as string)

here is ScanDirectory() code


private void ScanPluginDirectory()
= new AggregateCatalog();
.Catalogs.Add(new DirectoryCatalog(@"..\..\plugin"));            
= new CompositionContainer(catalog);
= new CompositionBatch();
= new Dictionary<String, String>();
foreach (IFilter filter in filters)
Type t = filter.GetType();
.Add(filter.Name, t.Module.Name);

and show their name in a checkbox list. upon selection of dll from checkbox.

i have import statement as

public IEnumerable<IFilter> filters { get; set;

currently my program is running fine. what i did is when i check a plugin from checkbox list. it moves it into "loaded" directory and and they QueryPlugin() method looks into "loaded" directory to search for plugins.

upon unchecking plugin from checkbox list. i move it out of "loaded" directory...

What i want is to use batch.RemovePart() method to get rid of this rapid moving of dlls from one directory to other....

NOTE: i am not adding plugins manually into batch using

batch.AddPart(new DemoFilter1());

instead of this i used DirectoryCatalog();

May 19, 2009 at 9:12 PM

In your case I might suggest that you don't use DirectoryCatalog but instead create the AssemblyCatalog's yourself when scanning the directory. Then if you want to add/remove an assembly either add or remove the AssembyCatalog from your AggregateCatalog.