🚀 How to use “Invoke Method” in Studio?

📝Note: If you encounter the “Expression does not produce a value” error when attempting to use void methods within the Assign activity, you can try resolving this issue using the following method.

-> If you want to enhance your automation projects by using VB.NET or C# code, you can use the Invoke Method activity in UiPath Studio. This activity allows you to execute a method from a .NET class or an instance of a .NET object. For example, you can use the Invoke Method activity to add an item to a list, get the length of a string, or sort an array.

-> To use the Invoke Method activity, you need to follow these steps:

1. Drag and drop the Invoke Method activity from the Activities panel to the Designer panel.


2. In the Properties panel, configure the following properties:


– TargetType: If you want to invoke a static method from a .NET class, select the class name from the drop-down list or browse for it by clicking the ellipsis button. If you want to invoke an instance method from an object, leave this property empty.


– TargetObject: If you want to invoke an instance method from an object, provide the variable that holds the object as the value of this property. If you want to invoke a static method from a .NET class, leave this property empty.


– MethodName: Enter the name of the method you want to invoke or select it from the drop-down list that appears when you click inside the property field.


– Parameters: If the method requires any input or output parameters, click the ellipsis button to open the Parameters window. Here you can add, edit, or remove parameters and specify their direction (In, Out, or In/Out), type, and value.


3. If the method returns a value, you can store it in a variable by creating a new variable in the Output section of the Properties panel and assigning it to the Result property.

-> Here is an example of how to use the Invoke Method activity to add an item to a list of strings:

– Create a variable of type List<String> and assign it an initial value of {“Hello”, “World”}.
– Drag and drop an Invoke Method activity and configure its properties as follows:
– TargetObject: The variable that holds the list of strings.
– MethodName: Add
– Parameters: Click the ellipsis button and add one parameter with these settings:
– Direction: In
– Type: String
– Value: “UiPath”
– Run the workflow and check the value of the list variable. It should be {“Hello”, “World”, “UiPath”}.

That’s it for the guide on using the “Invoke Method” activity in UiPath Studio.

Happy automating!

Leave a comment

Hey There!

I’m a Technical Team Lead with expertise in UiPath and RPA, along with skills in test automation and software development.

I will be sharing technical content on my personal blog, as well as on the RPA Updates platform.

You can connect with me on LinkedIn and also find RPA Updates on LinkedIn and Instagram.