15
Vote

Lifetime scope error when enabling/disabling modules in multiple tenants in parallel

description

I've just ran into this error, when tried to enable/disable a given module on 6 tenants at once.

Server Error in '/' Application.

Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.

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.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.

Source Error:


Line 19: ***************************************************************/
Line 20:
Line 21: Func<dynamic, dynamic> Zone = x => Display(x); // Zone as an alias for Display to help make it obvious when we're displaying zones
Line 22:
Line 23: /* Inserting some ad hoc shapes

Source File: c:\inetpub\wwwroot\KS Gateway Pages\Themes\TheAdmin\Views\Layout.cshtml Line: 21

Stack Trace:


[ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.]
Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +407
Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy.<>c__DisplayClass4.<CreateDelegate>b__3(DisplayContext context) in c:\Work\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAttributeStrategy\ShapeAttributeBindingStrategy.cs:55
Orchard.DisplayManagement.Descriptors.<>c__DisplayClass5.<BoundAs>b__2(DisplayContext displayContext) in c:\Work\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:55
Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in c:\Work\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:179
Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in c:\Work\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:88
Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in c:\Work\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:71

comments

pszmyd wrote Mar 26, 2012 at 2:16 PM

It's happening randomly, though. You might have to try a couple of times (eg. enabling some module with a couple of dependencies, so the enabling process would take a bit longer) to repro.

kdnmih wrote Apr 10, 2012 at 10:06 PM

I have same problem. I install the orchard cms on Local IIS(windows 7).

BertrandLeRoy wrote Apr 10, 2012 at 11:11 PM

@kdnmih: you may be getting the same error message but it may not be the same problem.

BertrandLeRoy wrote Apr 11, 2012 at 5:13 PM

@kdnmih: if you have VS11 installed, you will have to either uninstall it or update ORchard to the latest in the 1.x branch. Orchard 1.4 is not compatible with VS11 Beta.

scharada wrote May 22, 2012 at 7:16 PM

it is happening to me too.

i am not running it from VS (i have both installed 10 and 11)

it seems to be happening everytime i open multiple pages of the site at the same time which was not happening before this last update.

could autofac be the issue ?
look at this link :
http://stackoverflow.com/questions/9340828/autofac-with-asp-net-webforms-instances-cannot-be-resolved-and-nested-lifetimes

Levitikon wrote Jun 1, 2012 at 4:17 PM

Could you explain how you're enabling a module for multiple tenants at once? I've been struggling with a quick way to enable modules for 50 some odd tenants. I came up with a batch file to do this:

call bin\Orchard.exe feature enable Contrib.RewriteRules /t:mysite1
call bin\Orchard.exe feature enable Contrib.RewriteRules /t:mysite2

But when I run this on a machine that's also running orchard in IIS with an active application pool, I run into the same error you described.

consigliory wrote Jun 24, 2012 at 8:07 PM

I have the same issue. Is there any work around it?

Piedone wrote Jul 12, 2012 at 6:49 PM

I noticed the same as scharada. I can pretty reliably reproduce this with opening multiple pages of the same site after a change to the source (something not static or Razor template, that means the instance gets recompiled)

Piedone wrote Jul 21, 2012 at 5:56 PM

Now I've accidentally found a reliable way to reproduce the error. Steps (may not all be necessary, but I write all of them just in case):

1) Edit some enabled module's .cs file to force a recompile.
2) Place a breakpoint in the same and start debugging (worth noting: I've tried this with Onestop.Tenants, so that means attaching a debugger to an already open IIS process, unlike hitting F5 that recompiles immediately).
3) Open a page that invokes the code with the breakpoint.
4) The breakpoint is hit. Let the execution continue, but after resuming immediately edit the same code and save.
5) Ideally the page you've opened is still loading. Hit refresh.
6) Before the breakpoint is hit the second time, the below exception comes up in Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy.ShapeAttributeBindingStrategy ln. 52.

I guess with sites on the server we can reproduce this occasionally when after a recompile somebody is fetching a page, but meanwhile somebody else enables/disables a module or the instance is updated from the repo.


System.ObjectDisposedException was unhandled by user code
Message=Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.
Source=Autofac
ObjectName=""
StackTrace:
   at Autofac.Core.Lifetime.LifetimeScope.CheckNotDisposed()
   at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
   at Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy.ShapeAttributeBindingStrategy.<>c__DisplayClass4.<CreateDelegate>b__3(DisplayContext context) in D:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAttributeStrategy\ShapeAttributeBindingStrategy.cs:line 52
   at Orchard.DisplayManagement.Descriptors.ShapeAlterationBuilder.<>c__DisplayClass3.<>c__DisplayClass5.<BoundAs>b__2(DisplayContext displayContext) in D:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:line 55
   at Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:line 179
   at Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:line 88
   at Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 71
   at Orchard.DisplayManagement.Implementation.DisplayHelper.Invoke(String name, INamedEnumerable`1 parameters) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 38
   at Orchard.DisplayManagement.Implementation.DisplayHelperFactory.DisplayHelperBehavior.InvokeMember(Func`1 proceed, Object target, String name, INamedEnumerable`1 args) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelperFactory.cs:line 27
   at ClaySharp.ClayBehaviorCollection.<>c__DisplayClass14.<>c__DisplayClass16.<InvokeMember>b__13() in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 29
   at ClaySharp.ClayBehaviorCollection.Execute(Func`1 proceed, Func`3 linker) in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 13
   at ClaySharp.ClayBehaviorCollection.InvokeMember(Func`1 proceed, Object self, String name, INamedEnumerable`1 args) in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 29
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at ASP._Page_Themes_Onestop_CustomAdmin_Views_Layout_cshtml.<Execute>b__42(Object x) in d:\Orchard\src\Orchard.Web\Themes\Onestop.CustomAdmin\Views\Layout.cshtml:line 21
   at CallSite.Target(Closure , CallSite , Func`2 , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at ASP._Page_Themes_Onestop_CustomAdmin_Views_Layout_cshtml.Execute() in d:\Orchard\src\Orchard.Web\Themes\Onestop.CustomAdmin\Views\Layout.cshtml:line 42
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.ShapeTemplateBindingStrategy.Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) in D:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:line 134
   at Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.ShapeTemplateBindingStrategy.<>c__DisplayClass26.<>c__DisplayClass28.<Discover>b__15(DisplayContext displayContext) in D:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:line 118
   at Orchard.DisplayManagement.Descriptors.ShapeAlterationBuilder.<>c__DisplayClass3.<>c__DisplayClass5.<BoundAs>b__2(DisplayContext displayContext) in D:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:line 55
   at Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:line 179
   at Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:line 88
   at Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 71
   at Orchard.DisplayManagement.Implementation.DisplayHelper.Invoke(String name, INamedEnumerable`1 parameters) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 38
   at Orchard.DisplayManagement.Implementation.DisplayHelperFactory.DisplayHelperBehavior.InvokeMember(Func`1 proceed, Object target, String name, INamedEnumerable`1 args) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelperFactory.cs:line 27
   at ClaySharp.ClayBehaviorCollection.<>c__DisplayClass14.<>c__DisplayClass16.<InvokeMember>b__13() in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 29
   at ClaySharp.ClayBehaviorCollection.Execute(Func`1 proceed, Func`3 linker) in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 13
   at ClaySharp.ClayBehaviorCollection.InvokeMember(Func`1 proceed, Object self, String name, INamedEnumerable`1 args) in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 29
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at Orchard.Mvc.ViewEngines.ThemeAwareness.LayoutAwareViewEngine.<>c__DisplayClass7.<FindView>b__5(ViewContext viewContext, TextWriter writer, IViewDataContainer viewDataContainer) in D:\Orchard\src\Orchard\Mvc\ViewEngines\ThemeAwareness\LayoutAwareViewEngine.cs:line 63
   at Orchard.Mvc.ViewEngines.ThemeAwareness.LayoutAwareViewEngine.LayoutView.Render(ViewContext viewContext, TextWriter writer) in D:\Orchard\src\Orchard\Mvc\ViewEngines\ThemeAwareness\LayoutAwareViewEngine.cs:line 90
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
InnerException:

Piedone wrote Jul 22, 2012 at 4:31 PM

OK, I can make the same repro steps with a vanilla instance.
Actually at point 4 if you edit the file while the code execution is on hold at the breakpoint it has the same effect then editing it after execution continues (not much of a surprise :-)).

sebastienros wrote Jul 22, 2012 at 4:38 PM

@Piedone, the repro steps you are describing are nothing to do with this bug which is a bout enabling two tenants at the same time. The one you describe had a similar one fixed for 1.4. I'll try to find how I had fixed it to see if a recent change broke it again. You might want to create another bug for this, so we know which ones we want to fix the sooner.

Piedone wrote Jul 22, 2012 at 5:32 PM

pszmyd wrote Jul 24, 2012 at 7:12 PM

@sebastienroe @Piedone: The underlying problem might be the same for all those "lifetime scope" errors, as they all happen when there is an ongoing shell termination/reloading. For some reason either the lifetime scope gets prematurely disposed, or there are some tasks running that should not be ran at that moment.

pszmyd wrote Jul 24, 2012 at 7:13 PM

Should be @sebastienros - sorry for the typo;)

LordSaul wrote Jun 7, 2013 at 8:58 AM

We get this same error when creating a new tenant within our deployed environment (Azure web role). Recycling the application pool seemed to make that error go away

pszmyd wrote Mar 18 at 7:40 PM

Reopening. This issue still stands. The cause is the work context accessor trying to create new context based on an already disposed shell.

sebastienros wrote Mar 18 at 11:25 PM

1.x ?