views:

301

answers:

1

Ok, another Sharepoint strange error. In my workflow I am getting this error:

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

this is when I wait for onTaskChange event. Everywhere on the internet people say that this happens when either correlation token or taskid are not set properly, however I've triple checked and even rebuilt from scratch and yet the same error.

And the weird thing is that once it helped if I moved the whole thing before a logtoHistory activity and not after it. I mean, that just doesn't make any sense to me.

With this case however, there is no logtohistory event and nothing I do gets me past the problem.

UPDATE: I found out this happens as soon as I bind afterproperties of the onTaskChange activity. ???

UPDATE: here is the image of the part of workflow that is giving me trouble: alt text

More and more it looks like some kind of designer bug in connection with correlation tokens. If i create a new task token on the createTask and then assign it to update task, oncreated and onchange task, but not CompleteTask it will work ok, until complete task (as expected), but if I also set the new token to the complete task it will fail on onChangeTask. If I delete the completeTask it will fail on the onChangeTask. WTF??

A: 

There might be a problem with correlation tokens here. Are you using a different correlation token than the one used for the whole workflow?

EDIT: Another question - are you setting the TaskID property of the task in your code? In my custom activities, I always bind the TaskID property of the CreateTask activity to a local field icTaskID. Then, I add a en event handler to the CreateTask activitie's methodInvoking event and inside that event, do the following

Me.icVisaTaskID = Guid.NewGuid
naivists
I am using a different token, specific for this task.
Robert Ivanc
Edited my answer, maybe you have a problem with the TaskID property?
naivists
yes, i am setting the taskId in the invoking handler of createTask. As I wrote in the updated question, this happens after I bind AfterProperties, if they are not bound it works ok.
Robert Ivanc
OK, I am binding the AfterProperties too. One thing to notice, the field you are binding to, has to be initialised. Eg. Public ocVisaStateChangAfterProperties As Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties = New Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties
naivists
it seems to be initialized as well. it is really weird, as there are some tasks in the same workflow that have afterproperties bound, yet are not experiencing this problem.
Robert Ivanc
Still I believe it must be some of the three - TaskID, CorrelationToken or AfterProperties, because the error you are getting shows Workflow Foundation yelling "in the database, I cannot find the item which should receive this event"
naivists