Given Key Was Not Present When Adding to Dictionary

I am getting the following error when trying to add a value to the dictionary. However, I am printing out the key and value right before adding to dictionary. I am also adding values to a different dictionary in the same manner elsewhere in the process so I am unsure why this is happening now.



As per error the key you are using is exactly not matching with the key present

The keys are even case sensitive


The dictionary is empty in this case though. It is failing to assign the first key/value pair

You aren’t getting that error when you’re adding it. You’re getting that error when you try to output the value, because the key doesn’t exist yet.

You can see in the screenshot that the Key and Value are being logged before the error


How are you assigning are you using liek below

Dict("Key") = "Value"


First initialize a dictionary variable using assign activity like this or in variable panel

myVariable = new Dictionary(Of String,String)

Then try to assign your key and value like this in assign activity itself

myVariable("Elizabeth") = "Smith"

You can use the same format in assign activity so the dictionary variable gets built every time

Hope this helps

Cheers @jpreziuso

Show the Assign you’re using to set the value in the dictionary.

Thank you for this. I was including the dictionary name on the value side of assign and it was causing the error

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.