WF 4.5应用动态更新例外

时间:2017-10-05 13:43:45

标签: workflow-foundation-4.5

创建StateMachine Workflow后,我想尝试使用DynamicUpdate。按照说明我创建更新映射,但是当我尝试应用它时,我得到以下错误:

未处理的类型' System.Activities.DynamicUpdate.InstanceUpdateException'发生在System.Activities.dll中的附加信息:更新映射与工作流定义不匹配。请确保这是此定义的正确映射,并且尚未手动更改序列化映射。

疑难解答详情:IdSpace与所有者''已经' 2'成员;预期' 1'。

如果修改现有转换的触发器,或者将条件或操作活动重新分配给新转换,则StateMachine不支持动态更新。

我在新版本中所做的就是添加epmty State并将指针连接到它。仍然存在的工作流程会产生此异常。

1 个答案:

答案 0 :(得分:0)

试试:

public static void UpdateWorkflowDynamic(string xaml)
    {
        StringReader sr = new StringReader(xaml);
        XmlReader xmlReader = XmlReader.Create(sr);
        XamlXmlReaderSettings settings = new XamlXmlReaderSettings
        {
            LocalAssembly = typeof(BookmarkDesign).Assembly
        };
        XamlReader xamlReader = new XamlXmlReader(xmlReader, settings);
        ActivityXamlServicesSettings XamlSettings = new ActivityXamlServicesSettings
        {
            CompileExpressions = true
        };
        Activity newActivity = ActivityXamlServices.Load(xamlReader, XamlSettings);


        sr = new StringReader(xaml);
        xmlReader = XmlReader.Create(sr);
        xamlReader = new XamlXmlReader(xmlReader, settings);
        ActivityBuilder activityBuilder = (ActivityBuilder)XamlServices.Load(ActivityXamlServices.CreateBuilderReader(xamlReader));
        DynamicUpdateServices.PrepareForUpdate(activityBuilder);
        DynamicUpdateMap updateMap = DynamicUpdateServices.CreateUpdateMap(activityBuilder);
        WorkflowIdentity newIdentity = new WorkflowIdentity
        {
            Name = "Update",
            Version = new Version(2, 0, 0, 0)
        };
        WorkflowApplicationInstance instance = WorkflowApplication.GetInstance(Guid.Parse("yourGuid"), GetInstance().InstanceStore);
        WorkflowApplication wfApp = new WorkflowApplication(newActivity, newIdentity);

        wfApp.Load(instance, updateMap);
        wfApp.Unload();
    }