I am using SharePoint 2013, VS2013 and Workflow engine 4.5. I have a custom Application page that I use for the next step in my workflow process. One the buttons on this page is a cancel button. When my users click this, I use ajax to call into my MVC web application. My MVC5.0 application I first update my Entity Framework database record then try to cancel the workflow.
Below is my MVC code. Why am I getting ExecutionEngineException error at this line clientContext.Load(instances); Note: If the take the below code and copy it to a console application it works!
//cancel the workflow
ClientContext clientContext = new ClientContext(baseUrl);
WorkflowServicesManager wfsm = new WorkflowServicesManager(clientContext, clientContext.Web);
WorkflowInstanceService instanceService = wfsm.GetWorkflowInstanceService();
WorkflowInstanceCollection instances = instanceService.EnumerateInstancesForListItem(listId, itemId);
**clientContext.Load(instances);**
clientContext.ExecuteQuery();
foreach (WorkflowInstance instance in instances)
{
if (instance.Id == new Guid(instanceId))
{
instanceService.CancelWorkflow(instance);
}
}
Any help would be appreciated.