Wednesday, September 10, 2008

WF Error: event receiver context for Workflow is invalid

Error

I ran into an interesting error when building up some WF State Machine Workflows for SharePoint. I had no problems building some sequential workflows and then I started building a fairly complex State Machine Workflow and I got a really useless error message that gave me no insight at all:

Value cannot be null

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)

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)

I did some searching and came up with some links but none of them helped:

Resolution

If you are getting this error basically you have somehow messed up the TaskID, TaskProperties, AfterProperties, BeforeProperties, or even your CorrelationTokens. When I say messed up, these values have probably not been initialized correctly.

In my case, I had forgot to do TaskId = Guid.NewGuid(); in one of my CreateTask event handlers and bam, I got this error.

No comments: