This project has moved. For the latest updates, please go here.
4
Vote

AtomicComposition encountered an unexpected Exception

description

Getting the following error occasionally


ProcessEntry() failed. InvalidOperationException: AtomicComposition encountered an unexpected Exception, review InnerException for details.
Stack Trace:
at System.ComponentModel.Composition.Hosting.AtomicComposition.FinalComplete()
at System.ComponentModel.Composition.Hosting.AtomicComposition.Complete()
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.DetermineRejection(ComposablePartDefinition definition, AtomicComposition parentAtomicComposition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.IsRejected(ComposablePartDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.InternalGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.InnerCatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable1& exports)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable
1& exports)
at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable1& exports)
at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable
1& exports)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportsCore(Type type, Type metadataViewType, String contractName, ImportCardinality cardinality)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValueCore[T](String contractName, ImportCardinality cardinality)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValue[T](String contractName)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValueT

--------------------------Inner Exception--------------------------
AggregateException: One or more errors occurred.

NullReferenceException: Object reference not set to an instance of an object.
Stack Trace:
at Microsoft.Internal.Collections.WeakReferenceCollection1.<CleanupDeadReferences>b__0(WeakReference w)
at System.Collections.Generic.List
1.RemoveAll(Predicate1 match)
at Microsoft.Internal.Collections.WeakReferenceCollection
1.CleanupDeadReferences()
at Microsoft.Internal.Collections.WeakReferenceCollection`1.Add(T item)
at System.ComponentModel.Composition.Hosting.ImportEngine.StartSatisfyingImports(PartManager partManager, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ImportEngine.EngineContext.Complete()
at System.ComponentModel.Composition.Hosting.AtomicComposition.FinalComplete()

comments

AlexanderGross wrote Jul 4, 2014 at 7:50 PM

I've seen the inner exception as well. I have no idea where this may come from. Any hints from the team?
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Internal.Collections.WeakReferenceCollection`1.<CleanupDeadReferences>b__0(WeakReference w)
   at System.Collections.Generic.List`1.RemoveAll(Predicate`1 match)
   at Microsoft.Internal.Collections.WeakReferenceCollection`1.Add(T item)
   at System.ComponentModel.Composition.Hosting.ImportEngine.StartSatisfyingImports(PartManager partManager, AtomicComposition atomicComposition)
   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.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValueCore[T](String contractName, ImportCardinality cardinality)
   at my code

nazbrok wrote Jul 8, 2014 at 2:23 PM

I also sometimes experiment this issue and have no clue what the problem can be.
So far I get it while trying to access GetExportedValue<T> of a service exported as NonShared.

What does the cleanup of dead reference has to do there ? :|
Any help is welcome.

nazbrok wrote Jul 9, 2014 at 3:17 PM

Hi

I think my case it seems the error was related to a bad use of MEF in a multi thread environment.
MEF isn't thread safe and this is what did cause those exception when GetExportedValue was called in the same time by 2 diff threads..

http://blogs.microsoft.co.il/bnaya/2010/12/04/dynamic-mef-isnt-thread-safe-by-nature/
http://blogs.microsoft.co.il/zuker/2011/01/02/mef-thread-safety-and-getexportedvalue/

I just had to add (isThreadSafe = true) to the CompositionContainer constructor.

hope it helps.