Getting Assert failing in CompositionEngine.TrySatisfyImports with multiple threads

Apr 27, 2009 at 8:34 PM
I am running MEF (Version=2009.1.23.0) on a web server. I store the CompositionHost in a static variable as it is initialized only once. I have a test where I hit the server with lots of requests and most of the time I have no issues. About 10% of the time I get a assert. It looks like (from reflector) in CompositionEngine.TrySatisfyImports it is using a variable called _partStack. Things are pushed into it at the beginning of the function and things are popped out of it at the end. When things are popped, it checked to make sure the state is the same as the one previously pushed. Problem is something could be added in the meantime and the assert would fail. This assert is failing:

using (@lock = new WriteLock(this._lock))
        {
            ComposablePartState state2 = this._partStack.Pop();
            Assumes.IsTrue(partState == state2);
        }

Here is the callstack:

Microsoft.Internal.Assumes+InternalErrorException: Internal error occurred. Additional information: ''.
   at Microsoft.Internal.Assumes.Fail(String message)
   at Microsoft.Internal.Assumes.IsTrue(Boolean condition)
   at System.ComponentModel.Composition.Hosting.CompositionEngine.TrySatisfyImports(ComposablePart part, Boolean recomposeImports, Boolean registerForRecomposition)
   at System.ComponentModel.Composition.Hosting.CompositionEngine.SatisfyImports(ComposablePart part, Boolean registerForRecomposition)
   at System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedObjectFromComposedPart(CompositionEngine engine, ComposablePart part, ExportDefinition definition)
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedObject(ComposablePart part, ExportDefinition export, Boolean isSharedPart)
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedObjectCore()
   at System.ComponentModel.Composition.Primitives.Export.GetExportedObject()
   at System.ComponentModel.Composition.ExportServices.StructuredValueExport`2.GetExportedObjectCore()
   at System.ComponentModel.Composition.Primitives.Export.GetExportedObject()
   at NationalInstruments.DiagramSdk.Composition.CompositionExtensions.CreateInstance[T](CompositionContainer container) in D:\src\lvaddon\NG\LV\Dev\p1\Trunk\DiagramSdk\Source\Composition\CompositionExtensions.WPF.cs:line 35
   at NationalInstruments.Labview.Compiler.Support.Internal.CompileAgent.Compile(CompileArgs args) in D:\src\lvaddon\NG\LV\Dev\p1\Trunk\Compiler.Support\Source\Internal\CompileAgent.cs:line 45
   at NationalInstruments.Labview.Compiler.Support.CompilerSupport.Compile(Stream sourceStream) in D:\src\lvaddon\NG\LV\Dev\p1\Trunk\Compiler.Support\Source\CompilerSupport.cs:line 65
   at NationalInstruments.Labview.Compiler.Support.SilverlightCompilerSupport.Compile(Stream sourceStream) in D:\src\lvaddon\NG\LV\Dev\p1\Trunk\Compiler.Support\Source\SilverlightCompilerSupport.cs:line 124
Developer
Apr 28, 2009 at 12:45 AM
While it is safe to share Catalogs among multiple threads, at this time it is not safe to use CompositionContainer or CompositionEngine across multiple threads. We are looking into to hardening these for multi-threaded scenarios.
Apr 28, 2009 at 1:44 PM

Thanks for the detailed information, we’ll certainly look into it.

In the meantime, can I suggest that you use a shared catalog, rather than a shared container, in your application? This is much less likely to run into any concurrency problems. The general approach is to store the container in Request[], and set it up/tear it down on Begin/EndRequest in the application class.

Nick

From: breeve [mailto:notifications@codeplex.com]
Sent: Monday, April 27, 2009 1:34 PM
To: Nicholas Blumhardt
Subject: Getting Assert failing in CompositionEngine.TrySatisfyImports with multiple threads [MEF:54640]

From: breeve

I am running MEF (Version=2009.1.23.0) on a web server. I store the CompositionHost in a static variable as it is initialized only once. I have a test where I hit the server with lots of requests and most of the time I have no issues. About 10% of the time I get a assert. It looks like (from reflector) in CompositionEngine.TrySatisfyImports it is using a variable called _partStack. Things are pushed into it at the beginning of the function and things are popped out of it at the end. When things are popped, it checked to make sure the state is the same as the one previously pushed. Problem is something could be added in the meantime and the assert would fail. This assert is failing:

using (@lock = new WriteLock(this._lock))
{
ComposablePartState state2 = this._partStack.Pop();
Assumes.IsTrue(partState == state2);
}

Here is the callstack:

Microsoft.Internal.Assumes+InternalErrorException: Internal error occurred. Additional information: ''.
at Microsoft.Internal.Assumes.Fail(String message)
at Microsoft.Internal.Assumes.IsTrue(Boolean condition)
at System.ComponentModel.Composition.Hosting.CompositionEngine.TrySatisfyImports(ComposablePart part, Boolean recomposeImports, Boolean registerForRecomposition)
at System.ComponentModel.Composition.Hosting.CompositionEngine.SatisfyImports(ComposablePart part, Boolean registerForRecomposition)
at System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedObjectFromComposedPart(CompositionEngine engine, ComposablePart part, ExportDefinition definition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedObject(ComposablePart part, ExportDefinition export, Boolean isSharedPart)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedObjectCore()
at System.ComponentModel.Composition.Primitives.Export.GetExportedObject()
at System.ComponentModel.Composition.ExportServices.StructuredValueExport`2.GetExportedObjectCore()
at System.ComponentModel.Composition.Primitives.Export.GetExportedObject()
at NationalInstruments.DiagramSdk.Composition.CompositionExtensions.CreateInstance[T](CompositionContainer container) in D:\src\lvaddon\NG\LV\Dev\p1\Trunk\DiagramSdk\Source\Composition\CompositionExtensions.WPF.cs:line 35
at NationalInstruments.Labview.Compiler.Support.Internal.CompileAgent.Compile(CompileArgs args) in D:\src\lvaddon\NG\LV\Dev\p1\Trunk\Compiler.Support\Source\Internal\CompileAgent.cs:line 45
at NationalInstruments.Labview.Compiler.Support.CompilerSupport.Compile(Stream sourceStream) in D:\src\lvaddon\NG\LV\Dev\p1\Trunk\Compiler.Support\Source\CompilerSupport.cs:line 65
at NationalInstruments.Labview.Compiler.Support.SilverlightCompilerSupport.Compile(Stream sourceStream) in D:\src\lvaddon\NG\LV\Dev\p1\Trunk\Compiler.Support\Source\SilverlightCompilerSupport.cs:line 124

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com