Assign: An item with the same key has already been added

i initialised a dictionary in one of my workflow and performed vlookup on it, in another workflow i have created and used another new dictionary. Now, while trying to use my new dictionary, i am getting error like “An item with the same key has already been added.” Can someone help me plss

Hi @Sirisha_Siri ,

A Dictionary contains unique keys i.e., no duplicate keys can be pushed into a Dictionary, although the values may be duplicate.

The expression you have used in the Assign Activity is generating duplicate keys, which is why you are running into the issue.

I would recommend outputting it to a DataTable first, just to see what values are getting populated before packaging it up inside of a Dictionary.

Kind Regards,
Ashwin A.K

Unfortunately we cannot see, what is used on RHS from the Assign.

Keys needs to be unique as Ashwin elaborated on. This duplicate key can occur in case of empty rows are involved. So check also for this while analysising the issue

Hi @ashwin.ashok

The below excel is the datatable which i am trying to access to perform vlookup. assign activity which is shown above contains vlookup query in LINQ.

CommentsOutput.xlsx (35.3 KB)

Hi @Sirisha_Siri ,

Would you be so kind as to also share the code that you have used to populate this dictionary with values?

Kind Regards,
Ashwin A.K

HI @ppr

Please check the below screenshot for assign activity RHS

Hi @ashwin.ashok

VLookupForComments.xaml (19.9 KB)

Please find the attached xaml code. This is only one of the workflow in the project, there are other workflows too

with the nature of join it could be the case that a duplicated value / row with same Join Col Value is creating a duplicated row.

Just check (manually or with a linq) if such data is present in the both datatables. And as mentioned above. remove all unneeded blank rows as well in advance

Hi @Sirisha_Siri ,

This is the issue →


The highlighted segment is an inner loop, and when the program enters that segment the value of i remains same for that duration, until it enters the next iteration, which is why you are running into a duplicate key reference.

You have to find another way to achieve whatever it was you were trying to achieve.

Kind Regards,
Ashwin A.K

Hi @ashwin.ashok

but the same code i have used in other workflow in same project and it is not resulting in any errors

looks like as mentioned above:

ensure that on the right datatable all GUID values are unique. Can you check this e.g. within the immediate panel?

Yes @ashwin.ashok , GUID Column contains duplicate values, how can i remove those?

what about the entire rows? Is is a duplicated row in relation to all columns as well?
If not, on how you want to handle, when the Message text are different?

Lets do one step back and have a more high level look on you Business case. Whats to achieve? What alternates can be available. Can you tell about or reference you case again? Thanks

Hi @ppr

i need to get the values of “message text” in “Comments output” excel, which is having same value in “Transaction Confirm Number” column in “ECC” Excel and “GUID” Column of “CommentsOutput” excel. So i am using LINQ Query to perform VLOOKUP ans extract the values. Please find the below sample excels.
CommentsOutput.xlsx (35.3 KB)

ECC To Investigate_21_3_2022.xlsx (632.8 KB)

Have a look here:

we do see a lot of duplicates related to GUID an message text

Maybe you can handle like follwoing:

dictLK = dtComments.DefaultView.ToTable(True, {“GUID”, “MessageText”}).toDictionary(Function (x) x(0).toString.Trim, Function (x) x(1).toString.Trim)

In case of it is failling a gain on duplicated key, then you will have a duplicated GUID with differen Message texts.
Can you try?

Hi @ppr

This helped…Thanks a lot

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