InvokeMethod Activity Designer

InvokeMethod designer is used to create and configure an InvokeMethod activity.

The InvokeMethod activity

The InvokeMethod calls a public method of a specified object or type.

Use the InvokeMethod Activity Designer

Access the InvokeMethod activity designer in the Primitives category of the Toolbox. The InvokeMethod activity designer can be dragged from the Toolbox and dropped on to the Workflow Designer surface where ever activities are usually placed, such as inside a Sequence. Dropping the activity designer creates an InvokeMethod activity with a default DisplayName of InvokeMethod. The DisplayName can be edited in the header of the InvokeMethod activity designer or in the DisplayName box of the property grid.

The InvokeMethod properties

The following table shows the InvokeMethod properties and describes how they're used in the designer. These properties can be edited in property grid, and some can be edited on Workflow Designer surface.

Property Name Required Usage
DisplayName False The friendly name of the InvokeMethod activity. The default value is InvokeMethod.

Although the DisplayName is not strictly required, it's best to use one.
MethodName True The name of the method to be called when the activity executes. The called method must be declared as public. This property can be edited on designer surface, and is mandatory.
Parameters False The parameter collection of the called method. The parameters must be added to the collection in the same order that they appear in the method signature. To display the Parameters dialog where you can set this property, click the ellipsis button in the Parameters field of the property grid. Click the Create Argument button to add the parameters.
Result False The return value of the method call.
RunAsynchronously True Specifies whether the method is called asynchronously. The default value is False.
TargetObject False The object that contains the method to call. This property can be edited on designer surface.

Either the TargetObject or the TargetType is required to be set.
TargetType False The type of TargetObject. This property can be edited on the designer surface. This property must only be set if the method called is static.

To pass parameters as a C# out parameter (for example, Method1(out myParam)), use OutArgument instead of InOutArgument

Methods with arguments called TargetObject or Result can't be invoked using the InvokeMethod activity. The reason for this is that InvokeMethod activity registers the GenericTypeArguments, TargetObject and Result in CacheMetadata.

The algorithm for registering the parameters in CacheMetadata is shown in the following list:

  1. Register TargetObject argument.

  2. Register Result argument.

  3. Iterate through the Parameters collection and register each argument.

The resulting exception is of type InvalidWorkflowException with the following message: 'InvokeMethod': A variable, RuntimeArgument or a DelegateArgument already exists with the name 'TargetObject'. Names must be unique within an environment scope.

This restriction doesn't apply to TargetType and RunAsynchronously. They're not workflow arguments and therefore aren't registered in the GenericTypeArguments collection of the InvokeMethod activity in the CacheMetadata method.

See also