locked
Failed to load workflow in WF 4.0 RRS feed

  • Question

  • After reshot Workflow Designer, I use WorkflowDesigner.Load(fileName)  to load a workflow from xaml file,  I got the following error

    System.ArgumentException: The service 'System.Activities.Design.Services.ModelService' has already been published by another object. ---> System.ArgumentException: An item with the same key has already been added.
       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       at System.Activities.Design.EditingContext.DefaultServiceManager.Publish(Type serviceType, Object serviceInstance)
       --- End of inner exception stack trace ---
       at System.Activities.Design.EditingContext.DefaultServiceManager.Publish(Type serviceType, Object serviceInstance)
       at System.Activities.Design.WorkflowDesigner.Load(Object instance)
       at System.Activities.Design.WorkflowDesigner.Load()

    Do I need to do anything before call WorkflowDesigner.Load(fileName)?

    Tuesday, July 21, 2009 10:58 PM

Answers

  • The best solution is to create a new instance of the workflowdesigner. The load method is really only for "initial" load. I believe you can use Designer.Context.Services.GetService<ModelService>().Root as well to interact with the Designer but I haven't tried it so I don't have any details. Again the best solution is to create a new instance of the workflowdesigner and load the new workflow.

    Thanks,
    Amy

    Thursday, September 10, 2009 1:01 AM

All replies

  • Hi,

    I don't know if it can help, but here is a code which works to load a workflow from a XAML file :

    Public Sub LoadExistingFlowchart(ByVal workflowPath As String)
         If workflowPath IsNot Nothing Then
             Dim _wd As New WorkflowDesigner
             _wd.Load(workflowPath)
             DesignerBorder.Child = _wd.View
             PropertyBorder.Child = _wd.PropertyInspectorView
         End If
    End Sub

    I use it to load Workflows to put them in the designer that I host in a window.
    • Edited by Shadew Wednesday, July 22, 2009 2:00 PM
    Wednesday, July 22, 2009 1:57 PM
  • DYin,

    Are you possible calling .Load a second time?

    Thanks,

    matt
    Program Manager -- wf designer -- http://blogs.msdn.com/mwinkle
    Wednesday, July 22, 2009 8:42 PM
  • Yes,  as I did not to create the designer instance again again.
    Thursday, July 23, 2009 6:13 AM
  • I don't find you to make two loads with a same instance. I create a new instance each time I must do a load.
    Thursday, July 23, 2009 7:09 AM
  • Is it a way to change the workflow loaded without recreating a new WorkflowDesigner ?

    Is there ressources used by the WorkflowDesigner to free (I think he doesn't unload the workflow because when I click on Variable Type > Browse for Types, there is a lot of "workflow" as empty namespace).
    Thursday, July 23, 2009 1:44 PM
  • The best solution is to create a new instance of the workflowdesigner. The load method is really only for "initial" load. I believe you can use Designer.Context.Services.GetService<ModelService>().Root as well to interact with the Designer but I haven't tried it so I don't have any details. Again the best solution is to create a new instance of the workflowdesigner and load the new workflow.

    Thanks,
    Amy

    Thursday, September 10, 2009 1:01 AM