How to use Invoke Method to Add items to Dictionary




I want to add items to a Dictionary using the Invoke Method activity and Add method.

Can you please tell me what should I supply in Parameters property for this?




May I advise you to open Manage Packages (Ctrl + P) and install the “Workflow Manager Activities”? Among these will be several activities related to Dictionary, including the one you need. Do make sure to initialise the dictionary variable before adding, either with a Build dictionary that adds no values by assigning New Dictionary(Of String, Integer) as the default value, or whichever pair of types you need. Also note that Build only accepts Result variables declared as IDictionary, while Add and Remove should also work with Dictionary as the declared type.



Hi Steven,

Thank you the response. I understand that there is an “Add to Dictionary” activity available for this task.

However, I want to know how to use the “Invoke Method” activity for this task and similar ones.
Let me briefly describe my query as below:

  1. I have my Dictionary variable dict setup as below.

  1. And I use the Invoke Method Activity as below.


  1. And I have the properties for the Invoke Method Activity as below.


Now I want to do something likes this: dict.Add(“key3”, “value3”) using UiPath. So what should I provide in the Parameters property of the Invoke Method activity?



Ah, sorry for misunderstanding your intent. The parameters should be of the same type and in the same order as would go into the written call. In your case the keys and values are both String, so the Parameters should be like so:

Unfortunately, “Invoke Method” does not have anything like the IntelliSense prompt. It will detect if there is a mistake in the arguments, but the feedback is not as clear as you would otherwise get; that’s why I personally try to avoid it by using more specific activities or, in the new community edition, the Code activity. However, InvokeMethod will work fine if you use it as shown.


Thank you Steven! That helped.