Share via


Using Custom Activities with Workflow MarkupĀ 

If you use custom activities in your workflow markup code, you must have the assemblies that contain those custom activities referenced in your host workflow code upon compilation. To do this, the assembly containing your custom activity must be referenced through a type provider in your code as shown in the following example:

// Add referenced assemblies to the TypeProvider.
TypeProvider typeProvider = new TypeProvider(null);
typeProvider.AddAssembly(typeof(CustomActivity).Assembly);
workflowRuntime.AddService(typeProvider);

In addition, if you use the command-line utility wfc.exe to compile your workflows, the assembly that contains that custom type must be added to the ReferencedAssemblies in your host application code as shown in the following example:

// Create a string array with all the assemblies you need to compile your workflow.
String [] assemblyNames = { "CustomWorkflowAssembly.dll" }
WorkflowCompilerParameters parameters = new WorkflowCompilerParameters(assemblyNames);

// Add the path to your referenced assembly to the collection.
parameters.ReferencedAssemblies.Add(typeof(CustomActivity).Assembly.Location);
' Create a string array with all the assemblies you need to compile your workflow.
Dim assemblyNames as String () = { "CustomWorkflowAssembly.dll" }
Dim parameters as New WorkflowCompilerParameters(assemblyNames)

' Add the path to your referenced assembly to the collection.
parameters.ReferencedAssemblies.Add(GetType(CustomActivity).Assembly.Location)

You must also add the clr-namespace value to your workflow markup file as shown in the following example:

xmlns:ns0="clr-namespace:XamlWithRules;Assembly=XamlWithRules, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

The following example shows a completed workflow markup file that declares a simple sequential workflow with a single instance of a CustomActivity activity.

<SequentialWorkflowActivity x:Class="XAMLWorkflow.Workflow1" x:Name="Workflow1" xmlns:ns0="clr-namespace:BusinessActivities;Assembly=CustomActivityAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" xmlns="https://schemas.microsoft.com/winfx/2006/xaml/workflow">
<ns0:CustomActivity x:Name="CustomActivity1"/>
</SequentialWorkflowActivity>

See Also

Concepts

Using Workflow Markup

Footer image

Send comments about this topic to Microsoft.