Sunday, 14 June 2009

InvalidOperationException "The event receiver context for Workflow is invalid" Problems with onTaskChanged in a SharePoint Workflow

As also mentioned here:

http://thorprojects.com/blog/archive/2006/11/30/invalidoperationexception-quote-the-event-receiver-context-for-workflow-is-invalid-quote-problems-with-ontaskchanged-in-a-sharepoint-workflow.aspx

If your OnTaskChanged activity is failing and your SharePoint ULS logs are showing something like the following:

06/14/2009 16:50:22.30 w3wp.exe (0x1548) 0x0208 Windows SharePoint Services Workflow Infrastructure 72ev Medium Value cannot be null. 06/14/2009 16:50:24.12 w3wp.exe (0x1548) 0x0208 Windows SharePoint Services Workflow Infrastructure 72ev Medium Value cannot be null. 06/14/2009 16:50:24.40 w3wp.exe (0x1548) 0x0208 Windows SharePoint Services Workflow Infrastructure 72er Medium System.InvalidOperationException: The event receiver context for Workflow is invalid. at Microsoft.SharePoint.SPEventReceiverDefinition.ValidContext() at Microsoft.SharePoint.SPEventReceiverDefinition.ValidReceiverFields() at Microsoft.SharePoint.SPEventReceiverDefinition.GetSqlCommandToAddEventReceivers(IList`1 erds) at Microsoft.SharePoint.Workflow.SPWinOESubscriptionService.CommitNewSubscriptions(Transaction txn, IList`1 erds) 06/14/2009 16:50:24.41 w3wp.exe (0x1548) 0x0208 Windows SharePoint Services Workflow Infrastructure 72fe High Error in commiting pending workflow batch items: System.InvalidOperationException: The event receiver context for Workflow is invalid. at Microsoft.SharePoint.SPEventReceiverDefinition.ValidContext() at Microsoft.SharePoint.SPEventReceiverDefinition.ValidReceiverFields() at Microsoft.SharePoint.SPEventReceiverDefinition.GetSqlCommandToAddEventReceivers(IList`1 erds) at Microsoft.SharePoint.Workflow.SPWinOESubscriptionService.CommitNewSubscriptions(Transaction txn, IList`1 erds) at Microsoft.SharePoint.Workflow.SPPendingWorkBatch.ProcessWorkItemBatch(Transaction transaction, Work method, IList`1 workItemBatch) at Microsoft.SharePoint.Workflow.SPPendingWorkBatch.Commit(Transaction transaction, ICollection items) 06/14/2009 16:50:24.47 w3wp.exe (0x1548) 0x0208 Windows SharePoint Services Workflow Infrastructure 88xr Unexpected WinWF Internal Error, terminating workflow Id# 82d5bb47-18c9-4fa1-a730-121984a7b435

Then you have probably done the following:

  1. Not assigned a Task Id variable to your OnTaskChanged Handler
  2. Assigned the wrong Task Id variable to the OnTaskChanged Handler.
  3. A combination of 1 and 2

I had mistakenly bound my OnTask changed handler in a Parallel workflow to a new variable rather than the existing TaskId variable I set during the Create Task Handler (so the Task Ids didn't match, hence the exception).

1 comment:

123 said...

It was rather interesting for me to read this article. Thanx for it. I like such topics and everything that is connected to this matter. I would like to read a bit more soon.
Alex
Cell phone blocker