Reputation: 1267
I designed a Workflow in WF4 in visual studio . It is so simple and I only want to execute this in this way.
using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
System.Workflow.Runtime.WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Workflow1));//My workflow
instance.Start();
}
But when i execute this i get the following error.
The input workflow type must be an Activity.Parameter name: workflowType
Upvotes: 1
Views: 2054
Reputation: 131190
There is a similar discussion in Technet. The WorkflowRuntime class is part of Workflow Foundation 3 and doesn't work with WF4 types. It is included only for backwards compatibility. In fact, in 4.5 WorkflowRuntime is marked obsolete.
You are probably trying to use a System.Activities.Activity based workflow to WorkflowRuntime, which will raise the ArgumentException error you describe.
To host/run a WF4 workflow you should use one of the following classes: WorkflowInvoker, WorkflowApplication and WorkflowServiceHost. This is described in the documentation, in Using WorkflowInvoker and WorkflowApplication.
The simplest way is to use WorkflowInvoker to run a workflow as a method, eg:
Activity wf = new WriteLine
{
Text = "Hello World."
};
WorkflowInvoker.Invoke(wf);
although this doesn't give you much control over the workflow's lifecycle.
WorkflowApplication gives you full control and WorkflowServiceHost allows you to host the workflow as a WCF service.
In fact, you can host a WF4 workflow using Windows Server AppFabric without creating your own host and let AppFabric manage instances, security and recovery.
Upvotes: 2