Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 0 down vote accepted

My ultimate goal to get this workflow to run is to grab the updated property in the OnTaskChanged, but as said before, this error'd out. So rather than trying to get the property from the workflowProperties.Item, I ended up calling the Lists Web service to get the item and the property. Disgusting, but it works.

share|improve this answer

Keep in mind the principles of how workflow is supposed to work. Workflows are designed to run asynchronously from your code. All the data in them gets serialized down into a standardized format that is then re-hydrated and acted upon, so make sure that your objects contain only primitives which you will use to re-initialize all of your complex objects and access. It looks like this is what you did in edit 3, good work.

It is also possible that while you are firing the event that activates the workflow on the Requesting thread, the actual execution of your code is happening on a background thread, perhaps a timer job or some other invoked thread. This can cause objects to be disposed in the wrong order as they may not share their data correctly between the threads.

Also, wouldn't you be better off to use a State Machine workflow? I have never had any success with the sequential ones, not saying you can't use them but I never managed to get them to work.

share|improve this answer

Tim, Its been a while since I have done workflow but I dont remember having similar problems.

Can you check that the correlation token is shared between the task activities.

One method you could use is to create your own SPWeb object using the workflowProperties.WebId and workflowProperties.SiteId properties. Once you have the SPWeb object, access the list and then the list item. Perform your modifications and then dispose of the SPWeb and SPSite objects.

Let us know how you get on.

Regards Simon

share|improve this answer
    
The correlation tokens match, and are specific to only these activities. I don't think it is a token issue as I'm hitting the OnTaskChanged event when expected. See my Edit 3 RE: workaround –  Tim Gabrhel Nov 10 '11 at 14:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.