Using SharePoint 2013 on Windows Server 2012 Standard.
I believe this is an issue with permissions. When trying to start a workflow on a staging server, the following exception happens (as shown in UlsViewer).
Exception occured in scope Microsoft.SharePoint.WorkflowServices.WorkflowInstanceService.StartWorkflowOnListItem. Exception=System.ArgumentException: List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user. ---> Microsoft.SharePoint.Client.ResourceNotFoundException: List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user. - -- End of inner exception stack trace --- at Microsoft.SharePoint.SPListCollection.ItemByInternalName(String strInternalName, Boolean bThrowException) at Microsoft.SharePoint.SPListCollection.GetListById(Guid uniqueID, Boolean bThrowException) at Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider.StartWorkflowOnListItem(WorkflowSubscription subscription, Int32 itemId, IDictionary`2 payload) at Microsoft.SharePoint.WorkflowServices.WorkflowInstanceServiceServerStub.StartWorkflowOnListItem_MethodProxy(WorkflowInstanceService target, XmlNodeList xmlargs, ProxyContext proxyContext) at Microsoft.SharePoint.WorkflowServices.WorkflowInstanceServiceServerStub.InvokeMethod(Object target, String methodName, XmlNodeList xmlargs, ProxyContext proxyContext, Boolean& isVoid) at Microsoft.SharePoint.Client.ServerStub.InvokeMethodWithMonitoredScope(Object target, String methodName, XmlNodeList args, ProxyContext proxyContext, Boolean& isVoid)
The relevant code is the following:
var wfServicesManager = new WorkflowServicesManager(ctx, ctx.Web); var workflowDeploymentService = wfServicesManager.GetWorkflowDeploymentService(); var wfSubscriptionService = wfServicesManager.GetWorkflowSubscriptionService(); var wfSubscriptions = wfSubscriptionService.EnumerateSubscriptions(); ctx.Load(wfSubscriptions, wfSubs => wfSubs.Where(wfSub => wfSub.Name == "Someuniqname")); ctx.ExecuteQuery(); var wfSubscription = wfSubscriptions.First(); var wfInstanceService = wfServicesManager.GetWorkflowInstanceService(); var startParameters = new Dictionary<string, object>(); wfInstanceService.StartWorkflowOnListItem(wfSubscription, folioId, startParameters); ctx.ExecuteQuery();
The IIS Application Pool is running as the same user account as the SharePoint App Pool, which happens to be a system account. I don't know if that could be an issue (I don't think so?), but just pointing it out.
Ok, for some reason, when I added and installed the .WSP, and I attached the Workflow to the list, there are two different Workflow Subscriptions returned by the EnumerateSubscriptions. One is attached to the list and one isn't. I fixed it by doing EnumerateSubscriptionsByList and passing the List GUID.