This is the error I receive if I try to update the form before editing the task:
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)
WinWF Internal Error, terminating workflow Id# acf30817-ec17-4064-9dbc-2b6bd7efd51c
This is the error I receive if I edit the task (approve the document) before I update the form:
Engine RunWorkflow: System.Workflow.Activities.EventDeliveryFailedException: Event "OnTaskChanged" on interface type "Microsoft.SharePoint.Workflow.ITaskService" for instance id "b9efcc6b-f6ae-4bb0-8d29-cde4c728f4a7" cannot be delivered. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.Workflow.ComponentModel.Serialization.ActivitySurrogate.ActivitySerializedRef.System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(Object sender) at System.Runtime.Serialization.DeserializationEventHandler.Invoke(Object sender) at System.Runtime.Serialization.ObjectManager.RaiseDeserializationEvent() at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream) at System.Workflow.ComponentModel.Activity.Load(Stream stream, Activity outerActivity, IFormatter formatter) at System.Workflow.ComponentModel.Activity.Load(Stream stream, Activity outerActivity) at System.Workflow.Runtime.Hosting.WorkflowPersistenceService.RestoreFromDefaultSerializedForm(Byte[] activityBytes, Activity outerActivity) at Microsoft.SharePoint.Workflow.SPWinOePersistenceService.LoadWorkflowInstanceState(Guid instanceId) at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance) at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext context, WorkflowInstance workflowInstance) at System.Workflow.Runtime.WorkflowRuntime.GetWorkflow(Guid instanceId) at System.Workflow.Activities.WorkflowMessageEventHandler.EventHandler(Object sender, ExternalDataEventArgs eventArgs)
--- End of inner exception stack trace --- at
System.Workflow.Activities.WorkflowMessageEventHandler.EventHandler(Object sender, ExternalDataEventArgs eventArgs) at Microsoft.SharePoint.Workflow.SPWinOETaskService.RaiseEvent(SPWinOeWorkflow workflow, SPWorkflowEvent workflowEvent, Object workItem, IPendingWork workHandler) at Microsoft.SharePoint.Workflow.SPWinOeHostServices.Send(SPWinOeWorkflow winoeworkflow, SPWorkflowEvent e) at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(Guid trackingId, SPWorkflowHostService host, SPWorkflow workflow, Collection`1 events, TimeSpan timeOut)
The first error occurs in the w3wp.exe process, the second occurs in the owstimer.exe. Actually, the first error occurs regardless of updating the task first then updating the item.
I wrote history logs directly after the On***Changed events that report the values of my boolean values that get checked in my ifElse activities, and they get set correctly.
It seams that it hangs at the second On***Changed event. And I cannot find what is trying to write a null value.
Here's my code for the On***Changed activities:
OnWorkflowItemChanged:
Code Snippet
private void itemUpdatedWithFoodApproverInvoked(object sender, ExternalDataEventArgs e)
{
SPSite site = new SPSite("http://spserv");
SPWeb web = site.OpenWeb();
SPUser foodMgr = null;
secondMgrName = workflowProperties.Item["Manager Food Approval"].ToString();
foodMgr = GetSiteUser(web, secondMgrName);
if ((foodMgr.ToString() != null) || (foodMgr.ToString() != ""))
foodManagerNotBlank = true;
web.Close();
site.Close();
}
OnTaskChanged:
Code Snippet
private void onMgrTaskChanged(object sender, ExternalDataEventArgs e)
{
mgrIsApproved = bool.Parse(afterManagerTaskProperties.ExtendedProperties["mgrIsApproved"].ToString());
mgrIsRejected = bool.Parse(afterManagerTaskProperties.ExtendedProperties["mgrIsRejected"].ToString());
managerTaskProps.ExtendedProperties["mgrComments"] = afterManagerTaskProperties.ExtendedProperties["mgrComments"].ToString();
if (managerTaskProps.ExtendedProperties["mgrComments"].ToString() != "")
taskComments = managerTaskProps.ExtendedProperties["mgrComments"].ToString();
else
taskComments =
"None";
if (mgrIsRejected == true)
rejectedBy = managerTaskProps.AssignedTo;
}
What's odd is that the task item shows in progress if the task is updated first then the item; if the item is updated first then the task item is changed, it says not started.
So it hangs somewhere. I think something is going on when it dehydrates/rehydrates, but I am at a loss at this point, I may try recreating the state from scratch.