【问题标题】:MEF error "Only one batch can be composed at a time"MEF 错误“一次只能组成一个批次”
【发布时间】:2014-02-18 16:37:12
【问题描述】:

我有一个在 Azure 中提供网站的网络角色。该站点使用[Import] 属性来导入数据存储库。这在大多数情况下都可以正常工作,但在中等负载下,偶尔会出现 Currently composing another batch in this ComposablePartExportProvider. Only one batch can be composed at a time 错误。

如何解决此错误?它已经成为应用程序中一个相当有问题的瓶颈,我确信有一个(相对)快速修复......我应该注意我在 Nuget 中使用MEF.MVC4 程序集。

我的Global.asax.cs 调用RegisterMefApplication_Start() 上设置MEF 方面。

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;
}

我的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

【问题讨论】:

  • 你能解决这个问题吗?
  • @overslacked - 我们不得不放弃 MEF...

标签: c# azure mef azure-web-roles


【解决方案1】:

我通过不使用 MEF.MVC4 解决了这个问题,因为它的实现在中等负载时可能会出错(例如:同时有 100 个用户请求)。我用 MEF2 here

在 Application_Start() 中

 var catalog = new AggregateCatalog(new DirectoryCatalog("bin"));
 var container = new CompositionContainer(catalog, true);
 ControllerBuilder.Current.SetControllerFactory(new MefControllerFactory(container));
 GlobalConfiguration.Configuration.DependencyResolver = new MefDependencyResolver(container);
 CurrentContainer.SetCurrentContainer(container);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 2021-08-05
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多