I'm trying to add a feedback workflow to several lists with the BaseTemplate 101 via feature activated event receiver. I'm using SharePoint 2013

My problem is, that the first list works fine, but the second fails with the error:

An exception of type 'Microsoft.SharePoint.SPException' occurred in Microsoft.SharePoint.dll but was not handled in user code

Additional information: Exception from HRESULT: 0x80131904

If I leave the first list out, add the workflow to the second it will still fail at the third list and so on...

I already checked the content database, because several other sources said that the database might be full, but it isn't.

This is the code that I'm using in the EventReceiver. I marked the point at the end where the error happens.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        SPWeb web = properties.Feature.Parent as SPWeb;

        string taskListTitle = "WorkflowTasks";
        string historyListTitle = "Workflow History";

        SPWorkflowTemplate collectFeedbackWorkflowTemplate = null;

        //Initializing with workflow template IDs 
        Guid collectFeedbackWorkflowTemplateID = new Guid("3bfb07cb-5c6a-4266-849b-8d6711700407");

        //Get Lists
        SPListCollection lists = web.Lists;

        //Getting workflow template based on workflow id
        foreach (SPWorkflowTemplate template in web.WorkflowTemplates)
            string templateName = template.Name;
            if (template.Id.Equals(collectFeedbackWorkflowTemplateID))
                collectFeedbackWorkflowTemplate = template;

        //--------------------------- Create collect feedback workflow association.--------------------------------------

        SPWorkflowAssociation collectFeedbackWorkflowAssociation = SPWorkflowAssociation.CreateWebContentTypeAssociation(collectFeedbackWorkflowTemplate,

        //setting to specify that workflow can be started manually
        collectFeedbackWorkflowAssociation.AllowManual = true;

        //setting to specify that manage lists permissions is required for starting a workflow
        if (collectFeedbackWorkflowAssociation.AllowManual)
            SPBasePermissions emptyMask = SPBasePermissions.EmptyMask;
            emptyMask |= SPBasePermissions.ManageLists;
            collectFeedbackWorkflowAssociation.PermissionsManual = emptyMask;

        //setting to specify that workflow will be automatically started whenever a new item is added
        collectFeedbackWorkflowAssociation.AutoStartCreate = false;
        //setting to specify that workflow will be automatically started whenever an item is changed/edited
        collectFeedbackWorkflowAssociation.AutoStartChange = false;

        //Adding workflow association to list
        foreach (SPList list in lists)
            if ((int)list.BaseTemplate == 101)
                // Here is the point where it fails

Does anyone have an idea why I can add the workflow to one list but fails at the next?

1 Answer 1


Meanwhile I found out the answer myself.

My mistake was, that I tried to add the SAME SPWorkflowAssociation to every list. I found out that this generated an error in the database, because the code would add the same primary key each time - what isn't allowed obviously.

So I adjusted it that everytime I add the workflow to a list, I create a new SPWorkflowAssociation before. And that finally worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.