I have a workflow related to the content type. I try to disconnect it from the code from the event receiver in the same content type, so when the item is updated, if there is a certain condition (status = ready for review), I run it.
// This line finds the association of workflows
var assoc = properties.Web.ContentTypes["Experiment Document Set"] .WorkflowAssociations.GetAssociationByName("Experiment Review Workflow", ultureInfo.CurrentUICulture);
// I tried to use this line from what I found on the Internet, but it will return null
assoc = properties.Web.WorkflowAssociations .GetAssociationByName("Experiment Review Workflow", CultureInfo.CurrentUICulture);
The following line gives an error:
var result = properties.Web.Site.WorkflowManager .StartWorkflow(properties.ListItem, assoc,string.Empty, SPWorkflowRunOptions.Synchronous);
System.ArgumentException: The workflow could not be started because the workflow is associated with a content type that is not in the list. Before starting the workflow again, a content type must be added to the list.
To check this, I looked at the content type of the updated list item and correctly.
properties.ListItem.ContentType.Name "Experiment Document Set"
So, basically, I have a workfow related to the content type "Experiment Document Set". When I try to start the workflow from the event receiver in the "Experiment Document Set", I get a message that the content type "Set of experimental documents" does not exist in the list, which does not make sense.