Freigeben über


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();

Comments

  • Anonymous
    February 24, 2015
    Silly question. Should the Visual Studio 2010 custom activity project be upgraded to .NET Framework 4.5 or should it be built for .NET Framework 3.5? I tried both; if I do the latter, the project does not even build (all I get is the "Type or namespace name 'SharePoint' does not exist in the namespace 'Microsoft'" error messages); if, on the other hand, I do the former, then the project builds but I have a hard time deploying it even if I explicitly add the assembly the way this article shows. What am I doing wrong?

    Thanks,

    Boris
  • Anonymous
    May 18, 2015
    Thanks for the article with code even I have tried this code its working ..
    http://staygreenacademy.com/
  • Anonymous
    June 18, 2015
    If you migrate custom workflow activities from SharePoint 2010 to SharePoint 2013 you may receive error