views:

103

answers:

0

I have two workflowInstance instances, one created using the WorkflowRuntime.CreateWorkflow(Type) an another using WorkflowRuntime.CreateWorkflow(XamlReader). I then try to insert the former as a child activity of the first. I had this working on a little prototype but when I tried to incorporate it to my project it didn't work. It throws a ArgumentException (when I try to apply the changes) with the following error message: "The passed in activity must be a child activity in the same ActivityExecutionContext.\r\nParameter name: activity" string

try
{
    masterInstance = runtime.CreateWorkflow(typeof(MasterWorkflow), parameters);
}
catch (Exception exe)
{
    throw new WorkflowBuilderException("Unable to create master workflow", exe);
}
//Create Xaml workflow
try
{
    XmlReader reader = XmlReader.Create(sreader);
    xamlInstance = runtime.CreateWorkflow(reader);
}
catch (Exception exe)
{
    throw new WorkflowBuilderException("Unable to create xaml workflow", exe);
}
//Insert the Xaml workflow in the MasterWorkflow
try
{
    //masterInstance.Start();
    Activity act = masterInstance.GetWorkflowDefinition();
    WorkflowChanges changes = new WorkflowChanges(act);
    Activity xamlRootActivity = xamlInstance.GetWorkflowDefinition();
    changes.TransientWorkflow.Activities.Add(xamlRootActivity);
    masterInstance.ApplyWorkflowChanges(changes);
 }
 catch (Exception exe)
 {
     throw new WorkflowBuilderException("Unable to build workflow", exe);
 }