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

GetExportedValues very slow

Nov 11, 2009 at 9:56 AM

I am using a bog standard CompositionContainer to discover types in a dll not referenced by my project, like this :

var catalog = new DirectoryCatalog(di.FullName);

var container = new CompositionContainer(catalog);
var capabilities = container.GetExportedValues<MyType>();

This is one of the slowest things in my project, and according to my profiler, the vast majority of the time is spent doing AssemblyCatalog.GetExports, iterating through AttributedPartCreationInfo MoveNext.

Is there anything I can do to tune this, or make life easier for the container?

Nov 11, 2009 at 4:55 PM

Out of curiosity, how many assemblies are in the bin folder that is being iterated through?

There's a few options.

  • One common practice is to move all your extensions to a sub-folder, this way you are not iterating through ALL assemblies, but only the ones that have extensions.
  • You can cache part information in some sort of manfiest and then have a custom catalog that reads the manifest and only loads as necessary. We have an API called ReflectionModelServices that aids in this. If you look into our MEF samples, you'll see a caching sample that uses this API.



Nov 12, 2009 at 2:41 PM

It was about 100. When I moved it into its own directory it ran much quicker. Thanks.

Nov 13, 2009 at 7:00 AM

Cool, glad to help.