(MOSS 2007 32bit SP2)
I have a workflow which was developed in Visual Studio and is deployed as a feature and associated with my list. Items in that list are created programmatically, and the last step of the process is to look through the SPWorkflowAssociation collection on the list and start the WF which matches a specific name:
// code to create the list item & get the new item's index (itemIndex)...
foreach (Microsoft.SharePoint.Workflow.SPWorkflowAssociation flowAssoc in SPContext.Current.Web.Lists["{listname}"].WorkflowAssociations) {
if (flowAssoc.Enabled && flowAssoc.AllowManual && (flowAssoc.Name.Trim() == workflowNameToLookFor.Trim()))
SPContext.Current.Site.WorkflowManager.StartWorkflow(SPContext.Current.Web.Lists["{listname}"].Items[itemIndex], flowAssoc, flowAssoc.AssociationData, true);
}
(please forgive the ugly fully-qualified names and the constant re-fetching of the SPListItem, unless you think that's actually to blame somehow)
This has been in production use for months, where the workflow being started was a SharePoint Designer workflow. Now that I've deployed my custom WF (which has a different name) I'm getting some "odd behavior":
Everything works 100% if I (not the system account, but a site collection admin) run the code to create the item and start the workflow. But if any other user (even someone with Full Control on the site and all involved lists) does the same they get a generic "Error, An unexpected error has occurred" page from SharePoint, but the item was created correctly, there's no WF error associated with it (the WF history for the item is completely blank), and they can then manually start the specified workflow without any problem.
The only error being generated in ULS when this happens is:
Engine RunWorkflow: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.SharePoint.Workflow.SPWorkflowHostServiceBase.LoadInstanceData(Guid instanceId, Boolean& compressedData) 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 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)
If I change the name of the workflow I'm looking for to something which doesn't exist, there is no error at all (as my IF statement in the FOREACH never finds a match), so it's definitely finding my workflow and trying to start it.
But (again), if I look at the Workflow Status/History page on an item which generated the error, there is no error or record of the WF ever trying to start there, and from that page the user can manually start the workflow without a problem.
I am using an InfoPath Association Form for the WF, but if that was at the root of this (e.g. if I need to be passing something with its data/schema to WorkflowManager.StartWorkflow) I'd expect to see the same error for my Site Collection Admin user. I am not using any sort of WF Initiation Form.
I'm going nuts trying to find the source of this. Hoping someone has seen this ULS error or this sort of behavior before...