I have the following code:
public class Temp<T, TMetadata> { [ImportMany] private IEnumerable<Lazy<T, TMetadata>> plugins; public Temp(string path) { AggregateCatalog aggregateCatalog = new AggregateCatalog(); aggregateCatalog.Catalogs.Add(new DirectoryCatalog(path)); CompositionContainer container = new CompositionContainer(aggregateCatalog); container.ComposeParts(this); } public T GetPlugin(Predicate<TMetadata> predicate) { Lazy<T, TMetadata> pluginInfo; try { pluginInfo = plugins.SingleOrDefault(p => predicate(p.Metadata)); } catch {
I have one Temp object and I call GetPlugin() from multiple threads. Sometimes I encounter unusual composition errors that I could not find a way to reproduce. For instance:
"System.InvalidOperationException: Stack empty. at System.Collections.Generic.Stack`1.Pop() at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager, ComposablePart part, Boolean shouldTrackImports) at System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImports(ComposablePart part) at System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine, ComposablePart part, ExportDefinition definition) at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(CatalogPart part, ExportDefinition export, Boolean isSharedPart) at System.ComponentModel.Composition.ExportServices.GetCastedExportedValue[T](Export export) at System.Lazy`1.CreateValue() at System.Lazy`1.LazyInitValue() at Temp`2.GetPlugin(Predicate`1 predicate)..."
What could be the reason and how to cure this code?
source share