Problem with dictionary with queue items

Hello.


I created a dictionary with an int key and a queueItem value, and I want to add 5 elements to it. To do this, I read an element from the queue in a loop and try to add it using add, but I get an error.
image
What did I do wrong?

Hi @Arettu63

You need to initialize the dictionary before the loop and import UiPath.Core inside Invoke Code.

QueueItem is not recognized otherwise, that’s why Add() gives an error. After adding the import and initializing the dictionary, TransactionList.Add(item, TransactionItem) works fine.

Cheers

@Arettu63

What is the code you are trying inside the Invoke code?

I added the default value to the variable as New Dictionary(Of Integer, QueueItem), but the error still persists.

We can’t and don’t import inside the Invoke code. Avoid misguiding if you are not sure.

TransactionList.Add(item,TransactionItem)

@Arettu63

Use Assign activity instead of Invoke Code

TransactionList(item) = TrasnactionItem

Also follow the naming conventions to avoid confusion later on

dictTransactions(item) = TrasnactionItem
1 Like

Hi @Arettu63,
The error comes from the Invoke Code activity because you added extra Imports inside the code window. UiPath already imports System.Collections.ObjectModel automatically, so adding it again causes the compile error. Remove all Imports from the Invoke Code and keep only the line that adds to the dictionary, for example:

TransactionList.Add(item, TransactionItem)

Make sure the dictionary variable is passed as In/Out. After removing the duplicate imports the code will run correctly.

I only had one line inside the calling code “TransactionList.Add(item, TransactionItem)”, and the arguments were In/Out. I already found a solution, thanks.

(post deleted by author)

take a backup from XAML
Close UiPath Studio
Open the XAML directly in an text editor (notepad++)

Check line 12 and/or <x:String> and remove duplicated entries
Save XAML and Close editor

Open Studio and check if the issue is solved

I want to loop through this dictionary but I’m not quite sure what type of argument is used for each

@Arettu63

Just take a new For Each activity and pass the dictionary to iterate. Studio will automatically change the argument type to the suitable one.

In your case it should be this:

System.Collections.Generic.KeyValuePair<System.Int32, UiPath.Core.Queueltem>

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