I have a visual studio sequential workflow. In that workflow, I have a string property called AllowDisposition. When the workflow starts, I populate that value by doing workflowProperties.Item["FIELD NAME"].ToString(). This works all fine and dandy.
After the properties are set, I have a CreateTask activity, and an OnTaskChanged activity. The OnTaskChanged sits inside of a while loop. This loop has a declarative condition that is evaluating against my AllowDisposition variable.
I have a web part that the user interacts with. When they make their selection, it is completing the task and setting the value of AllowDisposition on the workflow item. So when that task is updated, I'm grabbing the updated AllowDisposition, and that gets me out of the loop.
I've noticed a few random workflow's don't continue on. They are stuck inside of that loop. In the SharePoint logs, I have the following error:
Detected use of SPRequest for previously closed SPWeb object. Please close SPWeb objects when you are done with all objects obtained from them, but not before. Stack trace: at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties.get_SuperUserWorkflow() at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties.get_Item() at Name.EligibleRecordsWF.WorkflowEligibleRecords.WorkflowEligibleRecords.OwnerDisposition_TaskChanged_Invoked(Object sender, ExternalDataEventArgs e)
Inside of the OnTaskChanged event, I have a single line of code, which performs AllowDisposition = workflowProperties.Item["FIELD NAME"].ToString(). As I said before, the issue is intermittent. When the workflow continues as expected, there's nothing in the logs. When I see that error in the log, the workflow doesn't continue. I am able to verify that the value on the field IS getting updated.
I am not doing anything with any SPWeb objects. I'm simply referencing the workflowProperties object, but NEVER closing.
tl;dr
- Workflow randomly hits blockquote'd error
- Workflow gets stuck trying to get a value
- Passed SPDisposeCheck
- Issue is intermittent
Edit 1
I just found that this error is actually occurring even at times that the workflow continues on as expected.
Edit 2
Following this request, there is an error
An SPRequest object was not disposed before the end of this thread. To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it.
The call stack for this error is tracing back to the OnTaskChanged method that is being hit (as mentioned above).
Edit 3
Still unable to figure this issue out. MS support seemed to think it might be a timing/synchronization issue..Introducing a delay activity immediately after the task is created resolves the issue...but the workflow some how gets stuck in an 'In Progress' state, and never completes.
I also tried a workaround...When the workflow starts, I create and populate 4 variables, 3 Guids (siteid, webid, listid), and an int (listitemId). These are serialized with the workflow so that I can reference them later.
using (SPSite site = new SPSite(_siteId))
{
using (SPWeb web = site.OpenWeb(_webId))
{
SPList list = web.Lists[_listId];
SPListItem item = list.GetItemById(_itemId);
AllowDisposition = item["AllowDisposition"];
}
}
This still has the same issue using this method.
Edit 4
I am able to get other properties, properties on the list item that have not changed since the workflow picked up, using the same method that I am getting AllowDisposition.