Migrating SharePoint 2010 workflow custom activity to SharePoint 2013

 This post is a contribution from Vitaly Lyamin, an engineer with the SharePoint Developer Support team.

For SharePoint 2010 custom activities to work in SharePoint 2013, the “authorizedType” node needs to be defined in a new sub-section “targetFx” under the “authorizedTypes” section. If this is not changed, an error will be encountered: ‘The type or namespace name '?' could not be found (are you missing a using directive or an assembly reference.'

Below is an example of how the authroizedTypes were setup in SharePoint 2010 vs how they should be setup in 2013  

SharePoint 2010:     

<System.Workflow.ComponentModel.WorkflowCompiler>

  <authorizedTypes>

      <authorizedTypeAssembly="Microsoft.Office.Workflow.Actions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Namespace="Microsoft.Office.Workflow.Actions"TypeName="*"Authorized="True" />

      <authorizedTypeAssembly="MyActions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234567"Namespace="MyActions"TypeName="*"Authorized="True" />

  </authorizedTypes>

  <authorizedRuleTypes>

      <authorizedTypeAssembly="Microsoft.SharePoint.WorkflowActions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Namespace="Microsoft.SharePoint.WorkflowActions"TypeName="WorkflowCodeTypeReferenceExpression"Authorized="True" />

  </authorizedRuleTypes>

</System.Workflow.ComponentModel.WorkflowCompiler> 

 

SharePoint 2013:

<System.Workflow.ComponentModel.WorkflowCompiler>

  <authorizedTypes>

    <targetFxversion="v4.0">

      <authorizedTypeAssembly="Microsoft.Office.Workflow.Actions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Namespace="Microsoft.Office.Workflow.Actions"TypeName="*"Authorized="True" />

      <authorizedTypeAssembly="MyActions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234567"Namespace="MyActions"TypeName="*"Authorized="True" />

    </targetFx>

  </authorizedTypes>

  <authorizedRuleTypes>

    <targetFxversion="v4.0">

      <authorizedTypeAssembly="Microsoft.SharePoint.WorkflowActions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"Namespace="Microsoft.SharePoint.WorkflowActions"TypeName="WorkflowCodeTypeReferenceExpression"Authorized="True" />

    </targetFx>

  </authorizedRuleTypes>

</System.Workflow.ComponentModel.WorkflowCompiler>

Modify the “SPWebConfigModification” code if needed:

var service = SPWebService.ContentService;

var addModification = new SPWebConfigModification();

addModification.Path = "configuration/System.Workflow.ComponentModel.WorkflowCompiler/authorizedTypes/targetFx";

addModification.Name= "authorizedType[@Assembly='MyActions'][@Namespace='MyActions'][@TypeName='*'][@Authorized='True']";

addModification.Owner= "MyActions";

addModification.Sequence= 0;

addModification.Type= SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

addModification.Value= @"<authorizedType Assembly=""MyActions""Namespace=""MyActions"" TypeName=""*""Authorized=""True"" />";

 service.WebConfigModifications.Add(addModification);

service.Update();

service.ApplyWebConfigModifications();