简体   繁体   中英

WF 4.5 Apply Dynamic Update Exception

After creating StateMachine Workflow with few steps i wanted to try using DynamicUpdate. By following the instructions i create update map, but when i try to apply it i get the following errors:

An unhandled exception of type 'System.Activities.DynamicUpdate.InstanceUpdateException' occurred in System.Activities.dll Additional information: The update map does not match the workflow definition. Please make sure that this is the correct map for this definition, and that the serialized map has not been manually altered.

Troubleshooting details: IdSpace with owner '' has '2' members; expected '1'.

StateMachine does not support Dynamic Update, if the Trigger of an existing Transition is modified, or the Condition or Action activity is reassigned to a new Transition.


All i did in the new version is adding epmty State and connect Pointers to it. Still the persisted workflows give this exception.

Try that:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM