Why is the Assign activity trying to assign an Object to a string?

  • I’m assigning a string value to the variable thisCSV in the Assign activity
  • thisCSV is of type String
  • I get the error:

“Cannot assign from type ‘System.Object’ to type ‘System.String’ in Assign activity ‘Assign’”

@x25115936

Please open advanced editor and give the same value in set value field and check if the error persists

cheers

I’m not sure what happened, but now it’s not complaining!

I tinkered around with a bunch of things, changed my variable to an Object then back to a String. Ran a separate sequence. Don’t know what I did, but it’s perfectly content now.

:man_facepalming:

To explain this abit more. The assign activity has a dynamic datatype based on the variable you are assigning to, by default its object but will transform to string etc when you add a string variable. This works on both sides of the assign.

Sometimes, that event doesn’t fire properly and it gets stuck thinking the variable is an object etc.
In scenarios like this, you can usually fix it by removing either the variable and adding it back, or doing the same for set value, this should force it to re-evaluate the data type.

Try by keeping set value like - “C:\Users\xxxx\Downloads\”.ToString

Hi @x25115936

What I often do myself when experiencing this issue:

  • Remove/re-add Variable and/or Value fields
  • Drag in a new Assign activity and fill it out again
  • Close/re-open the project

Regards
Soren

I encounter this quite often, mostly when I use assign, have some value stored on a clipboard, set it into the value property of the assign activity. Then, create a variable by setting the name property using ctrl-k for quick creation. If I then alter the datatype in the data manager this often happens.

The workaround is to just recreate the assign, set the values in a different sequence. Create variable, set the variable name in the assign, then the value never seems to fail.

For me a matter of unlearning some habits that don’t go well with the studio.

This usually happens when the variable on one side of the Assign is typed as a String, but the value you’re giving it is an Object. I’ve run into this a lot in UiPath. I’d check the variable types and either convert the Object with .ToString or change the target variable type if it should hold an Object instead.

Can you erase and add the variable again?