Misleading 'TypeArgument' property of the [Add To Collection]-activity - An Explanation!

To help others, the TypeArgument’ property is RELATED to the ‘ITEM’ property! It is NOT a property as a property meant to be related to the [Add To Collection]-activity. As its name should be self-explanatory, in my opinion, it is not.

Several users, including me, has faced trouble implementing an [Add To Collection]-activity, easily ending up with error messages like “…are you missing a cast?” because of ‘one type’ can’t be converted into ‘another type’ or whatever other ‘datatype’ mismatch, reason, misjudging the ‘property’ TypeArgument.

On several video’s, experienced users, explain the using of a ‘to my idea at least’ strange notation ‘ New List(Of String()) ’. Actually not for VB .Net users. Note, I have nothing against VB .Net honestly, don’t blame me, I simply lost connection with this directive. So, for C# users, new List() sounds more familiar.

An [Add To Collection]-activity is merely used in conjunction with setting up a list of attachments to be hooked on a [Send Mail Message]-activity.

An attachment list is just a list of comma separated strings, like in Python [“A”, “B”, “3”]. In C# UiPath such a list is instantiated as new List()

See screenshot: ‘attachmentList.

As in several tutorials, video’s, etc. is shown, an [Add To Collection]-activity is implemented within a [For Each]-activity. Each ‘item’ should be stored in that collection. Note, that such a collection can hold literally everything including a simple list of strings. This is actually the confusing trap!

The ‘TypeArgument’ property is RELATED to the ‘ITEM’ property and sure NOT to the ‘Collection’ property in the [Add To Collection]-activity.

Keep in mind, the ‘item’ is coming from the [For Each]-activity, most times it is simple string. The data type of the item is going to be the value of the TypeArgument. The ‘attachmentList’-variable, as said, is instantiated as a list of strings. This object is going to be filled up with strings of attachments.

This object (data typed as List in which T is a ‘string’) is hooked-up within the AttachmentCollection (data typed as InArgument<IEnumerable>).

Hello @k.vanderkamp!

It seems that you have trouble getting an answer to your question in the first 24 hours.
Let us give you a few hints and helpful links.

First, make sure you browsed through our Forum FAQ Beginner’s Guide. It will teach you what should be included in your topic.

You can check out some of our resources directly, see below:

  1. Always search first. It is the best way to quickly find your answer. Check out the image icon for that.
    Clicking the options button will let you set more specific topic search filters, i.e. only the ones with a solution.

  2. Topic that contains most common solutions with example project files can be found here.

  3. Read our official documentation where you can find a lot of information and instructions about each of our products:

  4. Watch the videos on our official YouTube channel for more visual tutorials.

  5. Meet us and our users on our Community Slack and ask your question there.

Hopefully this will let you easily find the solution/information you need. Once you have it, we would be happy if you could share your findings here and mark it as a solution. This will help other users find it in the future.

Thank you for helping us build our UiPath Community!

Cheers from your friendly