Thursday, September 19, 2013

System.InvalidOperationException: The event receiver context for Workflow is invalid.

Ever got this error while developing SharePoint 2010 Workflows in Visual Studio?

System.InvalidOperationException: The event receiver context for Workflow is invalid.
at Microsoft.SharePoint.SPEventReceiverDefinition.ValidContext()
at Microsoft.SharePoint.SPEventReceiverDefinition.GetSqlCommandToAddEventReceivers(IList`1 erds)
at Microsoft.SharePoint.Workflow.SPWinOESubscriptionService.CommitNewSubscriptions(Transaction txn, IList`1 erds)


Check the you have set the all the TaskIds in your code:

TaskId = Guid.NewGuid();

If this is not the case need to check that your Correlation Tokens are setup correctly.