Adding items to a dictionary



Hello Every body,

I am trying to use a data dictionary to storage my variables. However, when I use the activity “Add to dictionary” Uipath shows an error message which mentions the following “The dictionary has not been initialized”. My dictionary variable has a type System.Collections.Generic.Dictionary<TKey, TValue>

Can someone tell help me? What is missing? How can I must declare my variable to establish it as a data dictionary?



Before adding items to the dictionary it must be initialized. The default value of the Dictionar object is Nothing.

To initialize it you can use an Assign activity or define default value in the Variables pane.

The value should be new Dictionary(Of String, String), if both your key and value are strings.


How to get several "get row item" in UiPath

Hi Andra,
How do I assign a new value to my dictionary, I am trying to use the assign activity like data = data.Add(“hello”,“world”) where key is “hello” in this sample, but it cannot be done in that way, any suggestion?


If you’re working with dictionaries, I’d strongly suggest installing Microsoft.Activities.Extensions package - there’s a couple of very useful activities for them in there that will make your life easier.
Or you could use InvokeMethod, since .Add is void and thus cannot be used in Assign.



Although its bit late to reply, but it may help someone.

Use “Add to Dictionary” activity to add the Key and value in the Dictionary.