locked
Error updating workflow service running instances. RRS feed

  • Question

  • Hi,

         i have recently created a workflow service (xamlx) hosted on IIS which consist of a state machine with 2 different states with each state having a receive and send reply activity that causes the workflow runtime to persist the workflow to a database.

    I then created an update utility that can be used to dynamically update the running workflow instances in a database by following the tutorial at MSDN. However i received the following error whenever the util runs at

                                 "bool canUpdate = instance.CanApplyUpdate(map, out blocks);" 

    {"In order for an implementation map to be directly applied to a workflow instance, the root of the definition must not have any public children. The instance currently has one or more public children running."}

    I don't really get the meaning of the error message, the tool is suppose to update the running instance of the workflow. Any one has faced this issue and what's the solution? Please help.

    I have included the full source code and xamlx files for the update util at OneDrive

    thanks.

    Leonwoo

    Monday, October 20, 2014 8:19 AM

Answers

  • I found the solution at  https://code.msdn.microsoft.com/WF45-Developer-Preview-C-6e29ac28
    • Marked as answer by leonwoo Monday, October 27, 2014 6:58 AM
    Monday, October 27, 2014 6:58 AM

All replies

  • According to the error message above, this issue lies in the Workflow definition for dynamic update, you need check whether you use definition properly.
    Wednesday, October 22, 2014 10:51 AM
  • Hi SharpLj,

          thanks for the feedback. Could you please provide me with more insight on what has gone wrong with the workflow definition? Recently i have created a much simpler workflow service to test the Dynamic Update, it turns out to generate the same error. Here's the workflow codes:

    Testing.xamlx

    <WorkflowService mc:Ignorable="sap sap2010 sads" p1:TextExpression.Namespaces="{x:Reference __ReferenceID3}" p1:TextExpression.References="{x:Reference __ReferenceID4}" ConfigurationName="Testing" DefinitionIdentity="Testing; Version=1.0.0.0" sap2010:ExpressionActivityEditor.ExpressionActivityEditor="C#" sap2010:WorkflowViewState.IdRef="WorkflowService_1" Name="Testing"
     xmlns="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities"
     xmlns:p="http://tempuri.org/"
     xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/activities"
     xmlns:s="clr-namespace:System;assembly=mscorlib"
     xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
     xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
     xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
     xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
     xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
     xmlns:ssx="clr-namespace:System.ServiceModel.XamlIntegration;assembly=System.ServiceModel"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <p1:Sequence sap2010:WorkflowViewState.IdRef="Sequence_5">
        <p1:TextExpression.Namespaces>
          <sco:Collection x:TypeArguments="x:String" x:Name="__ReferenceID3">
            <x:String>System</x:String>
            <x:String>System.Collections.Generic</x:String>
            <x:String>System.Data</x:String>
            <x:String>System.Linq</x:String>
            <x:String>System.Text</x:String>
            <x:String>System.ServiceModel.Activities</x:String>
          </sco:Collection>
        </p1:TextExpression.Namespaces>
        <p1:TextExpression.References>
          <sco:Collection x:TypeArguments="p1:AssemblyReference" x:Name="__ReferenceID4">
            <p1:AssemblyReference>Microsoft.Activities</p1:AssemblyReference>
            <p1:AssemblyReference>Microsoft.Activities.Extensions</p1:AssemblyReference>
            <p1:AssemblyReference>Microsoft.CSharp</p1:AssemblyReference>
            <p1:AssemblyReference>Microsoft.Practices.EnterpriseLibrary.Common</p1:AssemblyReference>
            <p1:AssemblyReference>Microsoft.Practices.EnterpriseLibrary.ExceptionHandling</p1:AssemblyReference>
            <p1:AssemblyReference>Microsoft.Practices.EnterpriseLibrary.Logging</p1:AssemblyReference>
            <p1:AssemblyReference>System</p1:AssemblyReference>
            <p1:AssemblyReference>System.Activities</p1:AssemblyReference>
            <p1:AssemblyReference>System.Data</p1:AssemblyReference>
            <p1:AssemblyReference>System.Data.Entity</p1:AssemblyReference>
            <p1:AssemblyReference>System.Core</p1:AssemblyReference>
            <p1:AssemblyReference>System.ComponentModel.DataAnnotations</p1:AssemblyReference>
            <p1:AssemblyReference>System.Data.DataSetExtensions</p1:AssemblyReference>
            <p1:AssemblyReference>System.Data.Linq</p1:AssemblyReference>
            <p1:AssemblyReference>System.Runtime.Serialization</p1:AssemblyReference>
            <p1:AssemblyReference>System.ServiceModel</p1:AssemblyReference>
            <p1:AssemblyReference>System.ServiceModel.Activities</p1:AssemblyReference>
            <p1:AssemblyReference>System.ServiceModel.Channels</p1:AssemblyReference>
            <p1:AssemblyReference>System.Web.Extensions</p1:AssemblyReference>
            <p1:AssemblyReference>System.Xaml</p1:AssemblyReference>
            <p1:AssemblyReference>System.Xml.Linq</p1:AssemblyReference>
            <p1:AssemblyReference>System.Drawing</p1:AssemblyReference>
            <p1:AssemblyReference>System.Web</p1:AssemblyReference>
            <p1:AssemblyReference>System.Xml</p1:AssemblyReference>
            <p1:AssemblyReference>System.Configuration</p1:AssemblyReference>
            <p1:AssemblyReference>System.Web.Services</p1:AssemblyReference>
            <p1:AssemblyReference>System.EnterpriseServices</p1:AssemblyReference>
            <p1:AssemblyReference>System.Web.DynamicData</p1:AssemblyReference>
            <p1:AssemblyReference>System.Web.Entity</p1:AssemblyReference>
            <p1:AssemblyReference>System.Web.ApplicationServices</p1:AssemblyReference>
            <p1:AssemblyReference>mscorlib</p1:AssemblyReference>
          </sco:Collection>
        </p1:TextExpression.References>
        <p1:Sequence.Variables>
          <p1:Variable x:TypeArguments="CorrelationHandle" Name="CorHandle" />
          <p1:Variable x:TypeArguments="s:Guid" Name="CorId" />
        </p1:Sequence.Variables>
        <Receive x:Name="__ReferenceID0" CanCreateInstance="True" sap2010:WorkflowViewState.IdRef="Receive_4" OperationName="TestOpr1" ServiceContractName="p:IService">
          <Receive.CorrelatesOn>
            <XPathMessageQuery x:Key="key1">
              <XPathMessageQuery.Namespaces>
                <ssx:XPathMessageContextMarkup>
                  <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                </ssx:XPathMessageContextMarkup>
              </XPathMessageQuery.Namespaces>sm:body()/xgSc:TestOpr1/xgSc:p_CorId</XPathMessageQuery>
          </Receive.CorrelatesOn>
          <Receive.CorrelatesWith>
            <p1:InArgument x:TypeArguments="CorrelationHandle">
              <mca:CSharpValue x:TypeArguments="CorrelationHandle">CorHandle</mca:CSharpValue>
            </p1:InArgument>
          </Receive.CorrelatesWith>
          <Receive.CorrelationInitializers>
            <RequestReplyCorrelationInitializer>
              <RequestReplyCorrelationInitializer.CorrelationHandle>
                <p1:InArgument x:TypeArguments="CorrelationHandle">
                  <mca:CSharpValue x:TypeArguments="CorrelationHandle">CorHandle</mca:CSharpValue>
                </p1:InArgument>
              </RequestReplyCorrelationInitializer.CorrelationHandle>
            </RequestReplyCorrelationInitializer>
          </Receive.CorrelationInitializers>
          <ReceiveParametersContent>
            <p1:OutArgument x:TypeArguments="s:Guid" x:Key="p_CorId">
              <mca:CSharpReference x:TypeArguments="s:Guid">CorId</mca:CSharpReference>
            </p1:OutArgument>
          </ReceiveParametersContent>
        </Receive>
        <p1:Sequence sap2010:WorkflowViewState.IdRef="Sequence_6">
          <p1:WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_15" Text="Process A" />
          <p1:Delay sap2010:WorkflowViewState.IdRef="Delay_1">
            <p1:InArgument x:TypeArguments="x:TimeSpan">
              <mca:CSharpValue x:TypeArguments="x:TimeSpan">new TimeSpan(0,0,5)</mca:CSharpValue>
            </p1:InArgument>
          </p1:Delay>
          <p1:WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_16" Text="Process B" />
          <p1:WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_17" Text="Process C" />
        </p1:Sequence>
        <SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendReplyToReceive" sap2010:WorkflowViewState.IdRef="SendReply_4" />
        <p1:Sequence sap2010:WorkflowViewState.IdRef="Sequence_7">
          <p1:Sequence.Variables>
            <x:Reference>__ReferenceID2</x:Reference>
          </p1:Sequence.Variables>
          <Receive x:Name="__ReferenceID1" sap2010:WorkflowViewState.IdRef="Receive_5" OperationName="Operation1" ServiceContractName="p:IService">
            <Receive.CorrelationInitializers>
              <RequestReplyCorrelationInitializer>
                <RequestReplyCorrelationInitializer.CorrelationHandle>
                  <p1:InArgument x:TypeArguments="CorrelationHandle">
                    <p1:VariableValue x:TypeArguments="CorrelationHandle">
                      <p1:VariableValue.Variable>
                        <p1:Variable x:TypeArguments="CorrelationHandle" x:Name="__ReferenceID2" Name="__handle1" />
                      </p1:VariableValue.Variable>
                    </p1:VariableValue>
                  </p1:InArgument>
                </RequestReplyCorrelationInitializer.CorrelationHandle>
              </RequestReplyCorrelationInitializer>
            </Receive.CorrelationInitializers>
          </Receive>
          <p1:WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_18" Text="Process D" />
          <SendReply Request="{x:Reference __ReferenceID1}" DisplayName="SendReplyToReceive" sap2010:WorkflowViewState.IdRef="SendReply_5" />
        </p1:Sequence>
        <sads:DebugSymbol.Symbol>d01DOlxQcm9qZWN0c1xNZXN0YXJpXFJldmFtcFxNZXN0YXJpXE1lc3RhcmktUHJvZFxNZXN0YXJpLlNlcnZpY2VcVGVzdGluZy54YW1seBUPA4ABEQEBQQVdDwEcXgVnEwERaAVoiAEBCmkFfhMBAkwLTFsBI1oLWlQBIFMPU18BHV8HX1cBGmAHZBIBFmUHZVcBFGYHZlcBEm0HexEBCHwHfFcBBn0HfYoBAQNfSV9UARtiC2JeARdlSWVUARVmSWZUARNyEXYkAQl8SXxUAQc=</sads:DebugSymbol.Symbol>
      </p1:Sequence>
      <sap2010:WorkflowViewState.ViewStateManager>
        <sap2010:ViewStateManager>
          <sap2010:ViewStateData Id="Receive_4" sap:VirtualizedContainerService.HintSize="277,86" />
          <sap2010:ViewStateData Id="WriteLine_15" sap:VirtualizedContainerService.HintSize="211,62" />
          <sap2010:ViewStateData Id="Delay_1" sap:VirtualizedContainerService.HintSize="211,22" />
          <sap2010:ViewStateData Id="WriteLine_16" sap:VirtualizedContainerService.HintSize="211,62" />
          <sap2010:ViewStateData Id="WriteLine_17" sap:VirtualizedContainerService.HintSize="211,62" />
          <sap2010:ViewStateData Id="Sequence_6" sap:VirtualizedContainerService.HintSize="277,452">
            <sap:WorkflowViewStateService.ViewState>
              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
          </sap2010:ViewStateData>
          <sap2010:ViewStateData Id="SendReply_4" sap:VirtualizedContainerService.HintSize="277,86" />
          <sap2010:ViewStateData Id="Receive_5" sap:VirtualizedContainerService.HintSize="255,86" />
          <sap2010:ViewStateData Id="WriteLine_18" sap:VirtualizedContainerService.HintSize="255,62" />
          <sap2010:ViewStateData Id="SendReply_5" sap:VirtualizedContainerService.HintSize="255,86" />
          <sap2010:ViewStateData Id="Sequence_7" sap:VirtualizedContainerService.HintSize="277,438">
            <sap:WorkflowViewStateService.ViewState>
              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
          </sap2010:ViewStateData>
          <sap2010:ViewStateData Id="Sequence_5" sap:VirtualizedContainerService.HintSize="299,1306">
            <sap:WorkflowViewStateService.ViewState>
              <scg:Dictionary x:TypeArguments="x:String, x:Object">
                <x:Boolean x:Key="IsExpanded">True</x:Boolean>
              </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
          </sap2010:ViewStateData>
          <sap2010:ViewStateData Id="WorkflowService_1" sap:VirtualizedContainerService.HintSize="329,1376" />
        </sap2010:ViewStateManager>
      </sap2010:WorkflowViewState.ViewStateManager>
    </WorkflowService>

    Here's the generated xaml file from the Testing.xamlx

    <?xml version="1.0" encoding="utf-8"?>
    <Activity x:Class="{x:Null}" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities" xmlns:p="http://tempuri.org/" xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:p2="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib" xmlns:ssx="clr-namespace:System.ServiceModel.XamlIntegration;assembly=System.ServiceModel" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Sequence p2:DebugSymbol.Symbol="d01DOlxQcm9qZWN0c1xNZXN0YXJpXFJldmFtcFxNZXN0YXJpXE1lc3RhcmktUHJvZFxNZXN0YXJpLlNlcnZpY2VcVGVzdGluZy54YW1seBUPA4ABEQEBQQVdDwEcXgVnEwERaAVoiAEBCmkFfhMBAkwLTFsBI1oLWlQBIFMPU18BHV8HX1cBGmAHZBIBFmUHZVcBFGYHZlcBEm0HexEBCHwHfFcBBn0HfYoBAQNfSV9UARtiC2JeARdlSWVUARVmSWZUARNyEXYkAQl8SXxUAQc=">
        <TextExpression.Namespaces>
          <sco:Collection x:TypeArguments="x:String">
            <x:String>System</x:String>
            <x:String>System.Collections.Generic</x:String>
            <x:String>System.Data</x:String>
            <x:String>System.Linq</x:String>
            <x:String>System.Text</x:String>
            <x:String>System.ServiceModel.Activities</x:String>
          </sco:Collection>
        </TextExpression.Namespaces>
        <TextExpression.References>
          <sco:Collection x:TypeArguments="AssemblyReference">
            <AssemblyReference>Microsoft.Activities</AssemblyReference>
            <AssemblyReference>Microsoft.Activities.Extensions</AssemblyReference>
            <AssemblyReference>Microsoft.CSharp</AssemblyReference>
            <AssemblyReference>Microsoft.Practices.EnterpriseLibrary.Common</AssemblyReference>
            <AssemblyReference>Microsoft.Practices.EnterpriseLibrary.ExceptionHandling</AssemblyReference>
            <AssemblyReference>Microsoft.Practices.EnterpriseLibrary.Logging</AssemblyReference>
            <AssemblyReference>System</AssemblyReference>
            <AssemblyReference>System.Activities</AssemblyReference>
            <AssemblyReference>System.Data</AssemblyReference>
            <AssemblyReference>System.Data.Entity</AssemblyReference>
            <AssemblyReference>System.Core</AssemblyReference>
            <AssemblyReference>System.ComponentModel.DataAnnotations</AssemblyReference>
            <AssemblyReference>System.Data.DataSetExtensions</AssemblyReference>
            <AssemblyReference>System.Data.Linq</AssemblyReference>
            <AssemblyReference>System.Runtime.Serialization</AssemblyReference>
            <AssemblyReference>System.ServiceModel</AssemblyReference>
            <AssemblyReference>System.ServiceModel.Activities</AssemblyReference>
            <AssemblyReference>System.ServiceModel.Channels</AssemblyReference>
            <AssemblyReference>System.Web.Extensions</AssemblyReference>
            <AssemblyReference>System.Xaml</AssemblyReference>
            <AssemblyReference>System.Xml.Linq</AssemblyReference>
            <AssemblyReference>System.Drawing</AssemblyReference>
            <AssemblyReference>System.Web</AssemblyReference>
            <AssemblyReference>System.Xml</AssemblyReference>
            <AssemblyReference>System.Configuration</AssemblyReference>
            <AssemblyReference>System.Web.Services</AssemblyReference>
            <AssemblyReference>System.EnterpriseServices</AssemblyReference>
            <AssemblyReference>System.Web.DynamicData</AssemblyReference>
            <AssemblyReference>System.Web.Entity</AssemblyReference>
            <AssemblyReference>System.Web.ApplicationServices</AssemblyReference>
            <AssemblyReference>mscorlib</AssemblyReference>
          </sco:Collection>
        </TextExpression.References>
        <Sequence.Variables>
          <Variable x:TypeArguments="p1:CorrelationHandle" Name="CorHandle" />
          <Variable x:TypeArguments="s:Guid" Name="CorId" />
        </Sequence.Variables>
        <p1:Receive x:Name="__ReferenceID0" CanCreateInstance="True" OperationName="TestOpr1" ServiceContractName="p:IService">
          <p1:Receive.CorrelatesOn>
            <p1:XPathMessageQuery x:Key="key1">
              <p1:XPathMessageQuery.Namespaces>
                <ssx:XPathMessageContextMarkup>
                  <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                </ssx:XPathMessageContextMarkup>
              </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:TestOpr1/xgSc:p_CorId
            </p1:XPathMessageQuery>
          </p1:Receive.CorrelatesOn>
          <p1:Receive.CorrelatesWith>
            <InArgument x:TypeArguments="p1:CorrelationHandle">
              <mca:CSharpValue x:TypeArguments="p1:CorrelationHandle">CorHandle</mca:CSharpValue>
            </InArgument>
          </p1:Receive.CorrelatesWith>
          <p1:Receive.CorrelationInitializers>
            <p1:RequestReplyCorrelationInitializer>
              <p1:RequestReplyCorrelationInitializer.CorrelationHandle>
                <InArgument x:TypeArguments="p1:CorrelationHandle">
                  <mca:CSharpValue x:TypeArguments="p1:CorrelationHandle">CorHandle</mca:CSharpValue>
                </InArgument>
              </p1:RequestReplyCorrelationInitializer.CorrelationHandle>
            </p1:RequestReplyCorrelationInitializer>
          </p1:Receive.CorrelationInitializers>
          <p1:ReceiveParametersContent>
            <OutArgument x:TypeArguments="s:Guid" x:Key="p_CorId">
              <mca:CSharpReference x:TypeArguments="s:Guid">CorId</mca:CSharpReference>
            </OutArgument>
          </p1:ReceiveParametersContent>
        </p1:Receive>
        <Sequence>
          <WriteLine Text="Process A" />
          <Delay>
            <InArgument x:TypeArguments="x:TimeSpan">
              <mca:CSharpValue x:TypeArguments="x:TimeSpan">new TimeSpan(0,0,5)</mca:CSharpValue>
            </InArgument>
          </Delay>
          <WriteLine Text="Process B" />
          <WriteLine Text="Process C" />
        </Sequence>
        <p1:SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendReplyToReceive" />
        <Sequence>
          <Sequence.Variables>
            <x:Reference>__ReferenceID2</x:Reference>
          </Sequence.Variables>
          <p1:Receive x:Name="__ReferenceID1" OperationName="Operation1" ServiceContractName="p:IService">
            <p1:Receive.CorrelationInitializers>
              <p1:RequestReplyCorrelationInitializer>
                <p1:RequestReplyCorrelationInitializer.CorrelationHandle>
                  <InArgument x:TypeArguments="p1:CorrelationHandle">
                    <VariableValue x:TypeArguments="p1:CorrelationHandle">
                      <VariableValue.Variable>
                        <Variable x:TypeArguments="p1:CorrelationHandle" x:Name="__ReferenceID2" Name="__handle1" />
                      </VariableValue.Variable>
                    </VariableValue>
                  </InArgument>
                </p1:RequestReplyCorrelationInitializer.CorrelationHandle>
              </p1:RequestReplyCorrelationInitializer>
            </p1:Receive.CorrelationInitializers>
          </p1:Receive>
          <WriteLine Text="Process D" />
          <p1:SendReply Request="{x:Reference __ReferenceID1}" DisplayName="SendReplyToReceive" />
        </Sequence>
      </Sequence>
    </Activity>

    The workflow snapshot after calling the PrepareForUpdate on the Testing.xaml file.

    <?xml version="1.0" encoding="utf-8"?>
    <Activity x:Class="{x:Null}" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities" xmlns:p="http://tempuri.org/" xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:p2="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:sad="clr-namespace:System.Activities.DynamicUpdate;assembly=System.Activities" xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib" xmlns:ssx="clr-namespace:System.ServiceModel.XamlIntegration;assembly=System.ServiceModel" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <sad:DynamicUpdateInfo.OriginalActivityBuilder>
        <ActivityBuilder Name="{x:Null}">
          <Sequence p2:DebugSymbol.Symbol="d01DOlxQcm9qZWN0c1xNZXN0YXJpXFJldmFtcFxNZXN0YXJpXE1lc3RhcmktUHJvZFxNZXN0YXJpLlNlcnZpY2VcVGVzdGluZy54YW1seBUPA4ABEQEBQQVdDwEcXgVnEwERaAVoiAEBCmkFfhMBAkwLTFsBI1oLWlQBIFMPU18BHV8HX1cBGmAHZBIBFmUHZVcBFGYHZlcBEm0HexEBCHwHfFcBBn0HfYoBAQNfSV9UARtiC2JeARdlSWVUARVmSWZUARNyEXYkAQl8SXxUAQc=">
            <TextExpression.Namespaces>
              <sco:Collection x:TypeArguments="x:String">
                <x:String>System</x:String>
                <x:String>System.Collections.Generic</x:String>
                <x:String>System.Data</x:String>
                <x:String>System.Linq</x:String>
                <x:String>System.Text</x:String>
                <x:String>System.ServiceModel.Activities</x:String>
              </sco:Collection>
            </TextExpression.Namespaces>
            <TextExpression.References>
              <sco:Collection x:TypeArguments="AssemblyReference">
                <AssemblyReference>Microsoft.Activities</AssemblyReference>
                <AssemblyReference>Microsoft.Activities.Extensions</AssemblyReference>
                <AssemblyReference>Microsoft.CSharp</AssemblyReference>
                <AssemblyReference>Microsoft.Practices.EnterpriseLibrary.Common</AssemblyReference>
                <AssemblyReference>Microsoft.Practices.EnterpriseLibrary.ExceptionHandling</AssemblyReference>
                <AssemblyReference>Microsoft.Practices.EnterpriseLibrary.Logging</AssemblyReference>
                <AssemblyReference>System</AssemblyReference>
                <AssemblyReference>System.Activities</AssemblyReference>
                <AssemblyReference>System.Data</AssemblyReference>
                <AssemblyReference>System.Data.Entity</AssemblyReference>
                <AssemblyReference>System.Core</AssemblyReference>
                <AssemblyReference>System.ComponentModel.DataAnnotations</AssemblyReference>
                <AssemblyReference>System.Data.DataSetExtensions</AssemblyReference>
                <AssemblyReference>System.Data.Linq</AssemblyReference>
                <AssemblyReference>System.Runtime.Serialization</AssemblyReference>
                <AssemblyReference>System.ServiceModel</AssemblyReference>
                <AssemblyReference>System.ServiceModel.Activities</AssemblyReference>
                <AssemblyReference>System.ServiceModel.Channels</AssemblyReference>
                <AssemblyReference>System.Web.Extensions</AssemblyReference>
                <AssemblyReference>System.Xaml</AssemblyReference>
                <AssemblyReference>System.Xml.Linq</AssemblyReference>
                <AssemblyReference>System.Drawing</AssemblyReference>
                <AssemblyReference>System.Web</AssemblyReference>
                <AssemblyReference>System.Xml</AssemblyReference>
                <AssemblyReference>System.Configuration</AssemblyReference>
                <AssemblyReference>System.Web.Services</AssemblyReference>
                <AssemblyReference>System.EnterpriseServices</AssemblyReference>
                <AssemblyReference>System.Web.DynamicData</AssemblyReference>
                <AssemblyReference>System.Web.Entity</AssemblyReference>
                <AssemblyReference>System.Web.ApplicationServices</AssemblyReference>
                <AssemblyReference>mscorlib</AssemblyReference>
              </sco:Collection>
            </TextExpression.References>
            <Sequence.Variables>
              <Variable x:TypeArguments="p1:CorrelationHandle" Name="CorHandle" />
              <Variable x:TypeArguments="s:Guid" Name="CorId" />
            </Sequence.Variables>
            <p1:Receive x:Name="__ReferenceID3" CanCreateInstance="True" OperationName="TestOpr1" ServiceContractName="p:IService">
              <p1:Receive.CorrelatesOn>
                <p1:XPathMessageQuery x:Key="key1">
                  <p1:XPathMessageQuery.Namespaces>
                    <ssx:XPathMessageContextMarkup>
                      <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                    </ssx:XPathMessageContextMarkup>
                  </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:TestOpr1/xgSc:p_CorId
                </p1:XPathMessageQuery>
              </p1:Receive.CorrelatesOn>
              <p1:Receive.CorrelatesWith>
                <InArgument x:TypeArguments="p1:CorrelationHandle">
                  <mca:CSharpValue x:TypeArguments="p1:CorrelationHandle">CorHandle</mca:CSharpValue>
                </InArgument>
              </p1:Receive.CorrelatesWith>
              <p1:Receive.CorrelationInitializers>
                <p1:RequestReplyCorrelationInitializer>
                  <p1:RequestReplyCorrelationInitializer.CorrelationHandle>
                    <InArgument x:TypeArguments="p1:CorrelationHandle">
                      <mca:CSharpValue x:TypeArguments="p1:CorrelationHandle">CorHandle</mca:CSharpValue>
                    </InArgument>
                  </p1:RequestReplyCorrelationInitializer.CorrelationHandle>
                </p1:RequestReplyCorrelationInitializer>
              </p1:Receive.CorrelationInitializers>
              <p1:ReceiveParametersContent>
                <OutArgument x:TypeArguments="s:Guid" x:Key="p_CorId">
                  <mca:CSharpReference x:TypeArguments="s:Guid">CorId</mca:CSharpReference>
                </OutArgument>
              </p1:ReceiveParametersContent>
            </p1:Receive>
            <Sequence>
              <WriteLine Text="Process A" />
              <Delay>
                <InArgument x:TypeArguments="x:TimeSpan">
                  <mca:CSharpValue x:TypeArguments="x:TimeSpan">new TimeSpan(0,0,5)</mca:CSharpValue>
                </InArgument>
              </Delay>
              <WriteLine Text="Process B" />
              <WriteLine Text="Process C" />
            </Sequence>
            <p1:SendReply Request="{x:Reference __ReferenceID3}" DisplayName="SendReplyToReceive" />
            <Sequence>
              <Sequence.Variables>
                <x:Reference>__ReferenceID5</x:Reference>
              </Sequence.Variables>
              <p1:Receive x:Name="__ReferenceID4" OperationName="Operation1" ServiceContractName="p:IService">
                <p1:Receive.CorrelationInitializers>
                  <p1:RequestReplyCorrelationInitializer>
                    <p1:RequestReplyCorrelationInitializer.CorrelationHandle>
                      <InArgument x:TypeArguments="p1:CorrelationHandle">
                        <VariableValue x:TypeArguments="p1:CorrelationHandle">
                          <VariableValue.Variable>
                            <Variable x:TypeArguments="p1:CorrelationHandle" x:Name="__ReferenceID5" Name="__handle1" />
                          </VariableValue.Variable>
                        </VariableValue>
                      </InArgument>
                    </p1:RequestReplyCorrelationInitializer.CorrelationHandle>
                  </p1:RequestReplyCorrelationInitializer>
                </p1:Receive.CorrelationInitializers>
              </p1:Receive>
              <WriteLine Text="Process D" />
              <p1:SendReply Request="{x:Reference __ReferenceID4}" DisplayName="SendReplyToReceive" />
            </Sequence>
          </Sequence>
        </ActivityBuilder>
      </sad:DynamicUpdateInfo.OriginalActivityBuilder>
      <Sequence sad:DynamicUpdateInfo.MapItem="1" p2:DebugSymbol.Symbol="d01DOlxQcm9qZWN0c1xNZXN0YXJpXFJldmFtcFxNZXN0YXJpXE1lc3RhcmktUHJvZFxNZXN0YXJpLlNlcnZpY2VcVGVzdGluZy54YW1seBUPA4ABEQEBQQVdDwEcXgVnEwERaAVoiAEBCmkFfhMBAkwLTFsBI1oLWlQBIFMPU18BHV8HX1cBGmAHZBIBFmUHZVcBFGYHZlcBEm0HexEBCHwHfFcBBn0HfYoBAQNfSV9UARtiC2JeARdlSWVUARVmSWZUARNyEXYkAQl8SXxUAQc=">
        <TextExpression.Namespaces>
          <sco:Collection x:TypeArguments="x:String">
            <x:String>System</x:String>
            <x:String>System.Collections.Generic</x:String>
            <x:String>System.Data</x:String>
            <x:String>System.Linq</x:String>
            <x:String>System.Text</x:String>
            <x:String>System.ServiceModel.Activities</x:String>
          </sco:Collection>
        </TextExpression.Namespaces>
        <TextExpression.References>
          <sco:Collection x:TypeArguments="AssemblyReference">
            <AssemblyReference>Microsoft.Activities</AssemblyReference>
            <AssemblyReference>Microsoft.Activities.Extensions</AssemblyReference>
            <AssemblyReference>Microsoft.CSharp</AssemblyReference>
            <AssemblyReference>Microsoft.Practices.EnterpriseLibrary.Common</AssemblyReference>
            <AssemblyReference>Microsoft.Practices.EnterpriseLibrary.ExceptionHandling</AssemblyReference>
            <AssemblyReference>Microsoft.Practices.EnterpriseLibrary.Logging</AssemblyReference>
            <AssemblyReference>System</AssemblyReference>
            <AssemblyReference>System.Activities</AssemblyReference>
            <AssemblyReference>System.Data</AssemblyReference>
            <AssemblyReference>System.Data.Entity</AssemblyReference>
            <AssemblyReference>System.Core</AssemblyReference>
            <AssemblyReference>System.ComponentModel.DataAnnotations</AssemblyReference>
            <AssemblyReference>System.Data.DataSetExtensions</AssemblyReference>
            <AssemblyReference>System.Data.Linq</AssemblyReference>
            <AssemblyReference>System.Runtime.Serialization</AssemblyReference>
            <AssemblyReference>System.ServiceModel</AssemblyReference>
            <AssemblyReference>System.ServiceModel.Activities</AssemblyReference>
            <AssemblyReference>System.ServiceModel.Channels</AssemblyReference>
            <AssemblyReference>System.Web.Extensions</AssemblyReference>
            <AssemblyReference>System.Xaml</AssemblyReference>
            <AssemblyReference>System.Xml.Linq</AssemblyReference>
            <AssemblyReference>System.Drawing</AssemblyReference>
            <AssemblyReference>System.Web</AssemblyReference>
            <AssemblyReference>System.Xml</AssemblyReference>
            <AssemblyReference>System.Configuration</AssemblyReference>
            <AssemblyReference>System.Web.Services</AssemblyReference>
            <AssemblyReference>System.EnterpriseServices</AssemblyReference>
            <AssemblyReference>System.Web.DynamicData</AssemblyReference>
            <AssemblyReference>System.Web.Entity</AssemblyReference>
            <AssemblyReference>System.Web.ApplicationServices</AssemblyReference>
            <AssemblyReference>mscorlib</AssemblyReference>
          </sco:Collection>
        </TextExpression.References>
        <Sequence.Variables>
          <Variable x:TypeArguments="p1:CorrelationHandle" Name="CorHandle" />
          <Variable x:TypeArguments="s:Guid" Name="CorId" />
        </Sequence.Variables>
        <p1:Receive x:Name="__ReferenceID0" CanCreateInstance="True" sad:DynamicUpdateInfo.MapItem="28" OperationName="TestOpr1" ServiceContractName="p:IService">
          <p1:Receive.CorrelatesOn>
            <p1:XPathMessageQuery x:Key="key1">
              <p1:XPathMessageQuery.Namespaces>
                <ssx:XPathMessageContextMarkup>
                  <x:String x:Key="xgSc">http://tempuri.org/</x:String>
                </ssx:XPathMessageContextMarkup>
              </p1:XPathMessageQuery.Namespaces>sm:body()/xgSc:TestOpr1/xgSc:p_CorId
            </p1:XPathMessageQuery>
          </p1:Receive.CorrelatesOn>
          <p1:Receive.CorrelatesWith>
            <InArgument x:TypeArguments="p1:CorrelationHandle">
              <mca:CSharpValue x:TypeArguments="p1:CorrelationHandle" sad:DynamicUpdateInfo.MapItem="35">CorHandle</mca:CSharpValue>
            </InArgument>
          </p1:Receive.CorrelatesWith>
          <p1:Receive.CorrelationInitializers>
            <p1:RequestReplyCorrelationInitializer>
              <p1:RequestReplyCorrelationInitializer.CorrelationHandle>
                <InArgument x:TypeArguments="p1:CorrelationHandle">
                  <mca:CSharpValue x:TypeArguments="p1:CorrelationHandle" sad:DynamicUpdateInfo.MapItem="29">CorHandle</mca:CSharpValue>
                </InArgument>
              </p1:RequestReplyCorrelationInitializer.CorrelationHandle>
            </p1:RequestReplyCorrelationInitializer>
          </p1:Receive.CorrelationInitializers>
          <p1:ReceiveParametersContent>
            <OutArgument x:TypeArguments="s:Guid" x:Key="p_CorId">
              <mca:CSharpReference x:TypeArguments="s:Guid" sad:DynamicUpdateInfo.MapItem="32">CorId</mca:CSharpReference>
            </OutArgument>
          </p1:ReceiveParametersContent>
        </p1:Receive>
        <Sequence sad:DynamicUpdateInfo.MapItem="17">
          <WriteLine sad:DynamicUpdateInfo.MapItem="26">
            <InArgument x:TypeArguments="x:String">
              <Literal x:TypeArguments="x:String" sad:DynamicUpdateInfo.MapItem="27">Process A</Literal>
            </InArgument>
          </WriteLine>
          <Delay sad:DynamicUpdateInfo.MapItem="22">
            <InArgument x:TypeArguments="x:TimeSpan">
              <mca:CSharpValue x:TypeArguments="x:TimeSpan" sad:DynamicUpdateInfo.MapItem="23">new TimeSpan(0,0,5)</mca:CSharpValue>
            </InArgument>
          </Delay>
          <WriteLine sad:DynamicUpdateInfo.MapItem="20">
            <InArgument x:TypeArguments="x:String">
              <Literal x:TypeArguments="x:String" sad:DynamicUpdateInfo.MapItem="21">Process B</Literal>
            </InArgument>
          </WriteLine>
          <WriteLine sad:DynamicUpdateInfo.MapItem="18">
            <InArgument x:TypeArguments="x:String">
              <Literal x:TypeArguments="x:String" sad:DynamicUpdateInfo.MapItem="19">Process C</Literal>
            </InArgument>
          </WriteLine>
        </Sequence>
        <p1:SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendReplyToReceive" sad:DynamicUpdateInfo.MapItem="10" />
        <Sequence sad:DynamicUpdateInfo.MapItem="2">
          <Sequence.Variables>
            <x:Reference>__ReferenceID2</x:Reference>
          </Sequence.Variables>
          <p1:Receive x:Name="__ReferenceID1" sad:DynamicUpdateInfo.MapItem="8" OperationName="Operation1" ServiceContractName="p:IService">
            <p1:Receive.CorrelationInitializers>
              <p1:RequestReplyCorrelationInitializer>
                <p1:RequestReplyCorrelationInitializer.CorrelationHandle>
                  <InArgument x:TypeArguments="p1:CorrelationHandle">
                    <VariableValue x:TypeArguments="p1:CorrelationHandle" sad:DynamicUpdateInfo.MapItem="9">
                      <VariableValue.Variable>
                        <Variable x:TypeArguments="p1:CorrelationHandle" x:Name="__ReferenceID2" Name="__handle1" />
                      </VariableValue.Variable>
                    </VariableValue>
                  </InArgument>
                </p1:RequestReplyCorrelationInitializer.CorrelationHandle>
              </p1:RequestReplyCorrelationInitializer>
            </p1:Receive.CorrelationInitializers>
          </p1:Receive>
          <WriteLine sad:DynamicUpdateInfo.MapItem="6">
            <InArgument x:TypeArguments="x:String">
              <Literal x:TypeArguments="x:String" sad:DynamicUpdateInfo.MapItem="7">Process D - Modified Text</Literal>
            </InArgument>
          </WriteLine>
          <p1:SendReply Request="{x:Reference __ReferenceID1}" DisplayName="SendReplyToReceive" sad:DynamicUpdateInfo.MapItem="3" />
        </Sequence>
      </Sequence>
    </Activity>

    Here's the codes that i used to do PrepareForUpdate, generate update map, and to update running workflow instance.

    // Load the workflow definition from Xamlx into an ActivityBuilder and save it into a xaml file.
            XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings()
            {
                LocalAssembly = Assembly.GetExecutingAssembly()
            };
    
            XamlXmlReader xamlReader = new XamlXmlReader("Testing.xaml", readerSettings);
    
            WorkflowService s = XamlServices.Load(ActivityXamlServices.CreateBuilderReader(xamlReader)) as WorkflowService;              ActivityBuilder ab = new ActivityBuilder();
            ActivityBuilder ab = new ActivityBuilder();
            ab.Implementation = s.Body;
    
            var newPath =  "Testing.xaml";
            using (var writer = File.CreateText(newPath))
            {
                //Add the assembly references.
                List<Assembly> references = GetAssemblies();
    
                var xmlWriter = new XamlXmlWriter(writer, new XamlSchemaContext(references));
                using (var xamlWriter = ActivityXamlServices.CreateBuilderWriter(xmlWriter))
                {
                    XamlServices.Save(xamlWriter, ab);
                }
            }        
      
            //Load the xaml file and prepare it for update.
            XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings()
            {
                LocalAssembly = Assembly.GetExecutingAssembly()
            };
    
            //Add the assembly references - contain nothing at the moment.
            List<Assembly> references = GetAssemblies();
    
            XamlSchemaContext context = new XamlSchemaContext(references);
    
            XamlXmlReader xamlReader = new XamlXmlReader(newPath, readerSettings);
            
            var builderReader = ActivityXamlServices.CreateBuilderReader(xamlReader);
            ab = (ActivityBuilder)XamlServices.Load(builderReader);
            xamlReader.Close();
    
            DynamicUpdateServices.PrepareForUpdate(ab);
    
            //save the workflow snapshot into a xaml file.
    
            using (var writer = File.CreateText("wfReadyForUpdate.xaml"))
            {
                //Add the assembly references.
                List<Assembly> references = GetAssemblies();
    
                var xmlWriter = new XamlXmlWriter(writer, new XamlSchemaContext(references));
                using (var xamlWriter = ActivityXamlServices.CreateBuilderWriter(xmlWriter))
                {
                    XamlServices.Save(xamlWriter, ab);
                }
            }
    
            //Here I will modify the wfReadyForUpdate.xaml file with Visual studio designer.
            //I have tried to modify it just using a notepad.
            //The modification involves only very simple text change to the "Writeline" in the second Receive sequence.
            //After modify the xaml, I saved the file and generate the map file based on the modified file.
            //Load the wfReadyForUpdate.xaml
            XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings()
            {
                LocalAssembly = Assembly.GetExecutingAssembly()
            };
    
            //Add the assembly references.
            List<Assembly> references = GetAssemblies();
    
            XamlSchemaContext context = new XamlSchemaContext(references);
    
            XamlXmlReader xamlReader = new XamlXmlReader(filePath, readerSettings);
    
            ActivityBuilder ab;
            var builderReader = ActivityXamlServices.CreateBuilderReader(xamlReader);
            ab = (ActivityBuilder)XamlServices.Load(builderReader);
            xamlReader.Close();
    
            //create the update map
            DynamicUpdateMap map = DynamicUpdateServices.CreateUpdateMap(ab);
    
            //save the update map to a file "wfReadyForUpdate.map"
            DataContractSerializer serializer = new DataContractSerializer(typeof(DynamicUpdateMap));
            using (FileStream fs = System.IO.File.Open("wfReadyForUpdate.map", FileMode.Create))
            {
                serializer.WriteObject(fs, map);
            }
    
            //After the map is created i proceed to load a workflow instance that i have generated using the original workflow service from the database.
            string conn = System.Configuration.ConfigurationManager.ConnectionStrings["PersistanceStore"].ConnectionString;
            SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(conn);
    
            //load the map file
            DynamicUpdateMap map;
            using (FileStream fs = File.Open("wfReadyForUpdate.map", FileMode.Open))
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(DynamicUpdateMap));
                object updateMap = serializer.ReadObject(fs);
    
                if (updateMap == null)
                {
                    throw new ApplicationException("DynamicUpdateMap is null.");
                }
    
                map = (DynamicUpdateMap)updateMap;
            }
    
            //Load the original xaml file, Testing.xaml
            XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings()
            {
                LocalAssembly = Assembly.GetExecutingAssembly()
            };
    
                //Add the assembly references.
                List<Assembly> references = GetAssemblies();
    
                XamlSchemaContext context = new XamlSchemaContext(references);
    
                XamlXmlReader xamlReader = new XamlXmlReader("Testing_v1.xaml", readerSettings);
    
                ActivityBuilder originalDef;
                var builderReader = ActivityXamlServices.CreateBuilderReader(xamlReader);
                originalDef = (ActivityBuilder)XamlServices.Load(builderReader);
                xamlReader.Close();
    
    
            //Load the modified xaml file, wfReadyForUpdate.xaml
            XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings()
            {
                LocalAssembly = Assembly.GetExecutingAssembly()
            };
    
            //Add the assembly references.
            List<Assembly> references = GetAssemblies();
    
            XamlSchemaContext context = new XamlSchemaContext(references);
    
            XamlXmlReader xamlReader = new XamlXmlReader("wfReadyForUpdate.xaml", readerSettings);
    
            ActivityBuilder newDef;
            var builderReader = ActivityXamlServices.CreateBuilderReader(xamlReader);
            newDef = (ActivityBuilder)XamlServices.Load(builderReader);
            xamlReader.Close();
    
            try
            {
                List<Guid> workflowIds = GetPersistedWorkflowIds();
    
                if (workflowIds != null && workflowIds.Count() > 0)
                {                   
                    string reason = "";
    
                    foreach (Guid id in workflowIds)
                    {
    
                        WorkflowApplicationInstance instance = WorkflowApplication.GetInstance(id, store);                        
                        WorkflowIdentity identity = new WorkflowIdentity
                        {
                            Name = txtWorkflowIdentity.Text,
                            Version = new Version(1, 0, 0, 1)
                        };
    
                        // Load the persisted workflow instance using the original workflow definition
                        // but with an updated WorkflowIdentity.
                        WorkflowApplication wfApp = new WorkflowApplication(originalDef.Implementation, identity);
    
                        // Apply the dynamic update on the loaded instance.              
                        IList<ActivityBlockingUpdate> blocks = new List<ActivityBlockingUpdate>();
    
                        //Here throws the error message........
                        bool canUpdate = instance.CanApplyUpdate(map, out blocks);
    
                        foreach (var item in blocks)
                        {
                            reason += string.Format("Activity: {0}, Reason: {1} \r\n", item.Activity.DisplayName, item.Reason);
                        }
    
                        if (canUpdate)
                        {
                            wfApp.Load(instance, map);
                            wfApp.Unload();
                        }
                    }
    
                    if (reason != "")
                    {
                        Viewer v = new Viewer();
                        v.SetView(reason);
                    }                    
    
                    MessageBox.Show("Process Completed");
                }
                else MessageBox.Show("No workflow to update");
            }
            catch (Exception ex)
            {                                
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

    I have been trying to solve this for days, and i am still trying. Any hint on how to solve this is appreciated.

    thanks.

    Thursday, October 23, 2014 3:47 AM
  • I found the solution at  https://code.msdn.microsoft.com/WF45-Developer-Preview-C-6e29ac28
    • Marked as answer by leonwoo Monday, October 27, 2014 6:58 AM
    Monday, October 27, 2014 6:58 AM