TransactionScope problems

Topics: General, Troubleshooting
Jul 18, 2012 at 3:14 PM

Hi,

I'm using Orchard 1.4.3 downloaded from CodePlex. I started working on custom shop modules based on Bertrand Le Roy's Nwazet.Commerce and Skywalker's Orchard.WebShop modules.

From the very beginning of mixing this two modules, changing parts of it and adding other parts, I've occasionally stumbled upon this error:

Cannot access a disposed object.
Object name: 'TransactionScope'.

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: Cannot access a disposed object.
Object name: 'TransactionScope'.

Source Error: 


Line 41:                 if (!_cancelled) {
Line 42:                     Logger.Debug("Marking transaction as complete");
Line 43:                     _scope.Complete();
Line 44:                 }
Line 45: 

Source File: E:\Test Shop\src\Orchard\Data\TransactionManager.cs    Line: 43 

Stack Trace: 


[ObjectDisposedException: Cannot access a disposed object.
Object name: 'TransactionScope'.]
   System.Transactions.TransactionScope.Complete() +83955
   Orchard.Data.TransactionManager.System.IDisposable.Dispose() in E:\Excidis Shop\src\Orchard\Data\TransactionManager.cs:43
   Autofac.Core.Disposer.Dispose(Boolean disposing) +79
   Autofac.Util.Disposable.Dispose() +46
   Autofac.Core.Lifetime.LifetimeScope.Dispose(Boolean disposing) +57
   Autofac.Util.Disposable.Dispose() +46
   Orchard.Environment.DefaultOrchardHost.DisposeShellContext() in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardHost.cs:204
   Orchard.Environment.DefaultOrchardHost.<MonitorExtensions>b__6(AcquireContext`1 ctx) in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardHost.cs:189
   Orchard.Caching.Cache`2.CreateEntry(TKey k, Func`2 acquire) in E:\Excidis Shop\src\Orchard\Caching\Cache.cs:57
   Orchard.Caching.Cache`2.UpdateEntry(CacheEntry currentEntry, TKey k, Func`2 acquire) in E:\Excidis Shop\src\Orchard\Caching\Cache.cs:33
   Orchard.Caching.<>c__DisplayClass2.<Get>b__1(TKey k, CacheEntry currentEntry) in E:\Excidis Shop\src\Orchard\Caching\Cache.cs:21
   System.Collections.Concurrent.ConcurrentDictionary`2.AddOrUpdate(TKey key, Func`2 addValueFactory, Func`3 updateValueFactory) +81
   Orchard.Caching.Cache`2.Get(TKey key, Func`2 acquire) in E:\Excidis Shop\src\Orchard\Caching\Cache.cs:17
   Orchard.Caching.DefaultCacheManager.Get(TKey key, Func`2 acquire) in E:\Excidis Shop\src\Orchard\Caching\DefaultCacheManager.cs:33
   Orchard.Environment.DefaultOrchardHost.MonitorExtensions() in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardHost.cs:185
   Orchard.Environment.DefaultOrchardHost.BeginRequest() in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardHost.cs:213
   Orchard.Environment.DefaultOrchardHost.Orchard.Environment.IOrchardHost.BeginRequest() in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardHost.cs:78
   Orchard.Web.MvcApplication.HostBeginRequest(HttpApplication application, IOrchardHost host) in C:\Excidis Shop\src\Orchard.Web\Global.asax.cs:38
   Orchard.WarmupStarter.Starter`1.OnBeginRequest(HttpApplication application) in C:\Excidis Shop\src\Orchard.WarmupStarter\Starter.cs:68
   Orchard.Web.MvcApplication.Application_BeginRequest() in C:\Excidis Shop\src\Orchard.Web\Global.asax.cs:29

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +72
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +335
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
   System.Web.Util.ArglessEventHandlerProxy.Callback(Object sender, EventArgs e) +57
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Upon refreshing the page when seeing this message, another error pops up:

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 49: 
Line 50:         public void Terminate() {
Line 51:             using (var events = _eventsFactory()) {
Line 52:                 try {
Line 53:                     events.Value.Terminating();

Source File: E:\Test Shop\src\Orchard\Environment\DefaultOrchardShell.cs    Line: 51 

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.CheckNotDisposed() +57
   Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +59
   lambda_method(Closure ) +96
   Orchard.Environment.DefaultOrchardShell.Terminate() in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardShell.cs:51
   Orchard.Environment.DefaultOrchardHost.DisposeShellContext() in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardHost.cs:203
   Orchard.Environment.DefaultOrchardHost.<MonitorExtensions>b__6(AcquireContext`1 ctx) in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardHost.cs:189
   Orchard.Caching.Cache`2.CreateEntry(TKey k, Func`2 acquire) in E:\Excidis Shop\src\Orchard\Caching\Cache.cs:57
   Orchard.Caching.Cache`2.UpdateEntry(CacheEntry currentEntry, TKey k, Func`2 acquire) in E:\Excidis Shop\src\Orchard\Caching\Cache.cs:33
   Orchard.Caching.<>c__DisplayClass2.<Get>b__1(TKey k, CacheEntry currentEntry) in E:\Excidis Shop\src\Orchard\Caching\Cache.cs:21
   System.Collections.Concurrent.ConcurrentDictionary`2.AddOrUpdate(TKey key, Func`2 addValueFactory, Func`3 updateValueFactory) +81
   Orchard.Caching.Cache`2.Get(TKey key, Func`2 acquire) in E:\Excidis Shop\src\Orchard\Caching\Cache.cs:17
   Orchard.Caching.DefaultCacheManager.Get(TKey key, Func`2 acquire) in E:\Excidis Shop\src\Orchard\Caching\DefaultCacheManager.cs:33
   Orchard.Environment.DefaultOrchardHost.MonitorExtensions() in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardHost.cs:185
   Orchard.Environment.DefaultOrchardHost.BeginRequest() in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardHost.cs:213
   Orchard.Environment.DefaultOrchardHost.Orchard.Environment.IOrchardHost.BeginRequest() in E:\Excidis Shop\src\Orchard\Environment\DefaultOrchardHost.cs:78
   Orchard.Web.MvcApplication.HostBeginRequest(HttpApplication application, IOrchardHost host) in C:\Excidis Shop\src\Orchard.Web\Global.asax.cs:38
   Orchard.WarmupStarter.Starter`1.OnBeginRequest(HttpApplication application) in C:\Excidis Shop\src\Orchard.WarmupStarter\Starter.cs:68
   Orchard.Web.MvcApplication.Application_BeginRequest() in C:\Excidis Shop\src\Orchard.Web\Global.asax.cs:29

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +72
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +335
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
   System.Web.Util.ArglessEventHandlerProxy.Callback(Object sender, EventArgs e) +57
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

After getting this error, no matter how many refreshes, the error stays until I recycle the application pool.

I've searched through this forum and I found that you fixed TransactionScope errors in the 1.4 version but I use newer version which wasn't upgraded from previous versions and I still get the errors.

My pattern of usage when I'm getting this error is following:

- I'm browsing on the front-end to test shopping functionality, basically adding stuff to the cart, going to the checkout, choosing shipping company and placing an order. I'm doing this in incognito Google Chrome window because I'm using different user account for shopping than the one used at back-end for administration

- I switch to the back-end and click around a few times before getting this error. I realized that most of the time when I got this error was while disabling or enabling some modules but I'm not sure is that the only type of usage when I got the error.

 

Has this happened to anybody else?

And, more importantly, does anyone have a fix for this?