Error madness with variable type

Look at the screenshot.

The variable is of the String type. What I’m assigning is a cast of an object .ToString. So it’s a string, also.

Next activity it’s meant to use the variable (something I’ve been struggling with for the past hours, also, without any success) over a For Each with a list of items on the like of "{“monday”, “tuesday”, “wednesday”} provided in the string variable.

Now when running it’s throwing the silli error you see on the screenshot.

I’ve done this sort of assign a million times before without a problem.

Hi @pere

for variable IllistaDelItems which you have highlightedgive the variable type as System.Collections.Generic.List(System.String)

Regards,

You need to extract/split the data from the string first. This could be done with regex, for instance.

If you’d have the chance to define the string instead like this in the config

["monday", "tuesday", "wednesday"]

you could just deserialize it to a list:

var textString = config("mesos").ToString();
var list = JsonConvert.DeserializeObject<List<string>>(textString);
foreach (var day in list)
{
   // Do something with the item.
   Console.WriteLine(day);
}

Thanks to both of you.

It’s weird, because I have the same For Each activity that works flawless if I pass the info straight as a literal in the input text box:

Captura de pantalla 2023-11-29 133126

Now I want to use the same as a String that is stored in my Excel config file. Look at the pictures This is a provided in a standard example so I consider it being good practice.

Then when I try to provide that info, once it’s been read from the file and stored in a variable, there’s no way for me to do that. Al I get is it to iterate over each CHARACTER of the {“gen”,“feb”,“mar”,“abr”,“mai”,“jun”,“jul”,“ago”,“set”,“oct”,“nov”,“des”} string.

I have already changed the “type” in the activity parameters, from Object to String, trying to cast it to IEnumerator, whatever.

Yeah, I could change the string definition, but why is it so difficult to do the same as in the 1st screenshot but inside a string variable instead of a literal??

Which means you cannot iterate over it and as such you cannot use in a for each.

In .NET programming there is the concept of object inheritence.
What this means is that certain data types can inherit others, that might sound confusing but the way I try to describe it is to compare it to classifications of life.

We could say something is an Ape or a Dolphin or a Dog and these are give us a strong idea of what they are but they aren’t perfectly exact, an Ape could be a Chimpanzee, a Dog could be a labrador which would define them more strongly. A lab ‘inherits’ all the attributes of being a dog, but has perhaps some more traits.

If you zoom further out all those animals are mammals. This again classifies certain key characteristics but its still quite a vague / flexible type to give something.

Back to programming, for anything to be used in a For Each it needs to be able to be iterated over and this behaviour is defined by it inheriting the ‘IEnumerable’ interface much like a dog inherits the mammal type.

Lists inherit IEnumberable, Collections do, Arrays do etc etc.

String does not inherit IEnumerable, its just a singular object with one string in it. I realize you as a human see it as several strings but your data typing shows it is one big string.

You need to fix this, this can be done by doing a ‘Split’ on your string, stating the delimiter, but yours has the curly brackets so it maybe needs to be deserialized.

It looks like it used to be an IEnumerable but you forced it into a normal string along the way, perhaps when you did the object .ToString?
Maybe you can fix this simply by casting the object appropriately, we’d need to know the underlying type of the Object.

(for context every single type inherits ‘Object’, its the most basic type you can have an represents anything, as such you cannot really do much with it.)

Thats not a literal string, you are creating an array of strings.

@Jon_Smith ,

I don’t pretend to sound mean but… You don’t need to go as far as providing a lesson of Object Oriented Programming or paradigm… I’ve been working as a programming analyst for decades and got my Degree ages ago…

That said,

I’m writing “literal” because I’m getting really confused about the way Studio treats the info provided in the textbox of the For Each activity (1). You saw this screenshot, right?

Captura de pantalla 2023-11-29 133126

Well, I simply want that the “List of items” input text box treats my string as the same.

There’s a select for choosing the “Argument type” in the For Each activity. @Parvathy suggests to use a list of strings, but I have yet to figure out how to convert my string with “{“blah”, “ouch”}” to that. I wonder what’s the most straight forward way to accomplish (1).

When you write {"Settings", "Constants"} to somewhere in Studio, it is understood as an array of strings. If you write the same thing to an Excel cell, and read, you get a String (not an array).

@efelantti :smiley:

Then, again… how do I parse it as an array?

You can just deserialize it, as suggested. When you type it into Excel its just a string but what you type is a serialized array of strings.

Sorry if I Patronized on explaining the fundamentals, I figured the error would have been clear if those were understood so my misunderstanding.

1 Like

Easiest imo would be to change the definition of the string, like I already suggested. Then it’s a valid JSON list/array and can be deserialized as such. Otherwise you need to either transform it in code to a proper format or do some splitting manually.

1 Like

Ok, please excuse my stupidness.

In the end I did it following your suggestions and using these activities, as I couldn’t use the code you provided above:

Again, sorry if I sound stupid but I don’t think the way of doing this is smart at all. I had to change the format from {“xxxx”, “yyyy”} to [“xxx”, “yyy”], then use this Deserialize JSON Array and change the variable type to… JArray what?? Once I deserialize the JSON array, I would expect it to be of type standard array. But oh well, at least it works.

And now, let’s go back to the beginning, the bug report that opened this thread. First screenshot.

The error was thrown in the Assign activity. The data type of my variable was of String; the content I was trying to store in there was a String. Ignoring the fact that what I was trying to do further was incorrect, why in the world should I get that IEnumerable error in the assign activity??

I cannot confirm but when you use the Assign UiPath infers the data type you are assigning to and stores this in the xaml (you can inspect it in notepad), I would assume the data type of your variable originally was IEnumerable, at some point it got changed to string.
Usually studio will then correctly update the data type of the assign and change it from expecting an IEnumberable to a string, in some rare cases it does not.

I have experienced this myself a few times but cannot recreate it.
Removing the variable on the left side of the assign and re-adding it removes it.

1 Like

Yes @Jon_Smith , for sure I was messing around with the variable type before, but later I changed it, saved the project, restarted Studio… and the error stayed

Appreciate your input! Saved for future reference when troubleshooting arises.

1 Like

If its the error I state that will never help. The data type of the assign is baked into the XAML. You need to force Studio to recalc it by removing the variable in the assign and then re-adding it, that will make it examine the data type again and correct it.
Its a weird bug so hard to report, luckily doesn’t happen often but easy to fix if you do that.

I usually know workarounds or how to avoid triggering certain bugs.
But, of course, what I don’t want is them to happen, as this is paid software and it’s pricey, and it’s a hassle to have to deal with such an ammount of annoyances in your daily work, not to say how much it slows it down.

Agree, but as a fellow community member like you I cannot fix the bugs, but just help you with ‘coping strategies’.

Hopefully this can get fixed if it becomes more chronic, which I think it will be with coded workflows being more of a thing as I trigger it more often when using them.

1 Like

By the way, to whom it might concern:

I just created a new variable from scratch, of type Boolean.
I assigned a default value to it. No messing changing type whatsoever.
I tried using the variable in an “If” activity, it kept complaining about the variable to check being of type “Object”. I had to erase the variable name in the activity textfield and rewrite it several times until Studio finally wanted to accept that it was a Boolean.

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