I have a web role that serves a website in Azure. This site uses the attribute [Import]to import the data repository. This works fine for the most part, but with moderate workload random errors occur that say Currently composing another batch in this ComposablePartExportProvider. Only one batch can be composed at a time.
How to fix this error? This has become a rather problematic bottleneck in the application, and I'm sure there is a (relatively) quick fix ... I should note that I am using assembly MEF.MVC4in Nuget.
My Global.asax.cscalls RegisterMefto tune the MEF side for things on Application_Start().
public static void RegisterMef()
{
var container = ConfigureContainer();
ControllerBuilder.Current.SetControllerFactory(new MefControllerFactory(container));
GlobalConfiguration.Configuration.DependencyResolver = new MefDependencyResolver(container);
}
private static CompositionContainer ConfigureContainer()
{
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var container = new CompositionContainer(assemblyCatalog, true);
return container;
}
My CompositionContainer , . , SatifsyImportsOnce .
:
Currently composing another batch in this ComposablePartExportProvider. Only one batch can be composed at a time.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Currently composing another batch in this ComposablePartExportProvider. Only one batch can be composed at a time.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Currently composing another batch in this ComposablePartExportProvider. Only one batch can be composed at a time.]
System.ComponentModel.Composition.Hosting.ComposablePartExportProvider.Compose(CompositionBatch batch) +390
MEF.MVC4.MefControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +126
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +81
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +270
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +86
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12550511
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288