This project is read-only.

Cannot access a disposed object.

Topics: Administration, Customizing Orchard, General
Jul 30, 2012 at 3:45 AM
Edited Jul 30, 2012 at 3:48 AM

I'm getting this error wherever I try to enable or disable a module, a theme, or refresh page after edit cs code.



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: D:\Orchard.Source.1.5.1\src\Orchard\Data\TransactionManager.cs    Line: 43 




After long time deal with this error I realize that the reason is from my scheduled task handle



private readonly IScheduledTaskManager _taskManager;



private void ScheduleNextTask(DateTime date)
            if (date > DateTime.UtcNow)
                var tasks = _taskManager.GetTasks(TaskType);
                if (tasks == null || tasks.Count() == 0)
                    _taskManager.CreateTask(TaskType, date, null);



I comment any lines that use function from _taskManager, the error go away. But I don't know how to fix it, because I must use the _taskManager to check task and create task. 

Thanks for any help.

Jul 30, 2012 at 11:59 AM

These may be related: and

Jul 31, 2012 at 2:54 AM
Piedone wrote:

These may be related: and

Yes I already read that too, but I can not find anything that can fix my problem. My problem may be a bit different because when I comment all the lines with _taskManager, the error go away, I can enable/disable module or edit source file while running like normal

May 15, 2013 at 10:01 AM
Did you ever find a solution to this as I'm running into the same issue?
May 16, 2013 at 10:29 AM
I'd also be interested as I ran into this problem too.
Our scenario is we sync data from Microsoft Dynamics NAV to orchard (Items, Customers, salesprices etc). Once the tasks are enabled, just like above, enabling/disabling modules etc causes the error.
At first I just thought it was a dev machine issue and ignored it, but then I realised it affect the production servers too.

In the end, I created an API that called the same code as my tasks, then periodically call the api from an external source, works fine, but I would have rather the tasks do it.