I have the sample of sequence and what to add new activities dynamically
public class PageActivity: SequentialWorkflowActivity
{
public PageActivity()
{
CodeActivity code = new CodeActivity("ca1");
code.ExecuteCode +=
delegate { Console.WriteLine("bla"); };
Activities.Add(code);
}
}
now I'm trying to add new activities to my sequence and save it to the memory stream
private static void Main(string[] args)
{
CodeActivity code = new CodeActivity("ca2");
code.ExecuteCode +=
delegate { Console.WriteLine("bla-bla"); };
PageActivity pa = new PageActivity();
pa.Activities.Add(code);
Stream stream = new MemoryStream();;
pa.Save(stream);
...
}
and then start Workflow as
instance = workflowRuntime.CreateWorkflow(
XmlReader.Create(stream));
the problem is that in the pa.Save(stream); I got exception
"This is an invalid design time operation. You can only perform the operation at runtime."
How to fix it?
Is there another way to add activities and other WF entities dynamically?