Using ReadOnly variable to set initial variable value


As mentioned in past threads, when the error message, “This location is marked as const, so its value cannot be modified”, is encountered, it is due to a Read-Only variable attempting to be modified.

I noticed that I am also having problems when I try to use it on assignment to local variables. Why can I not set the initial value of a non-Read-Only local variable to a read only variable?


This is kind of goofy logic you’re trying to use here. You don’t set one variable to true and another to false and then check against those variables. True and false are values themselves, you don’t need them in variables. You’re making extra work for yourself.

Directory.Exists() returns boolean, so you can just do…


If for some reason you want to use the Path Exists activity, the result is that its output variable (pathExists, or whatever you named it) has a value of true or false, so you can just do…



Again, though, that’s extra work because you’re creating variables and splitting it into multiple steps/activities, when you can just directly use the Directory.Exists() method in one step.

The variable DoesNotExist is intended to act as a constant that avoids “Imaginary Boolean” values. So there is not a question on what the boolean value False actually represents. By setting it to a constant, the constant describes False.

The Path Exists activity could be removed entirely, as you recommend, as it does not seem too cluttered. I would probably want to put the string path in a constant variable to avoid a magic string.

The single variable conditions on the Boolean seem appropriate to me, however, I’ve seen single variable Boolean values that did not adequately describe the condition. When applied with constants they add additional context to the condition.

I appreciate the possible clean up of code, however, I’m still inquiring about the Read-Only variables being assigned to non-Read-Only variables.

If it helps, the logic you’re using is like setting a variable…

Assign myVar = 2

…and then doing…

If someValue = myVar

…in order to see if someValue is 2. That’s extra work, goofy logic. You just do…

If someValue = 2

…just like you can do…

If someBool = True

…but booleans are special in that you don’t even need the “= True” part…

If someBool

…is all you need.

Any word on the error message from assigning a Read-Only variable to a non-Read-Only variable?

Show which activity is faulting.

But why does it matter? You should use proper logic and then the error won’t happen.

The screenshots are still valid above. As mentioned some of the code could be refactored, however, a variable that is intended to be a read-only constant cannot be used for initialization.

In your example, you mentioned assigning a variable of 2 and then checking again later if it is 2. The number 2 could be added to a constant that describes 2, so we know more about what 2 represents. That way when our business logic executes, and possibly changes the value of myVar to 3, we know it no longer represents the condition that our read-only constant (of 2) describes. It also works well for reusability, if the constant should need to be referenced again later. However, in the current state of things, the constant could not be used for initialization before the bulk of the business logic is performed on it.

Also, I appreciate your time, and feedback.

Yes it can. That’s why I asked you to show which activity of yours is faulting, because it probably isn’t in the ones you showed.


That’s what documenting your code is for.

And, of course, in the context of true/false what else could they mean besides an expression being true or false?

Directory.Exists(path) is much easier to understand than the convoluted logic you’ve shown with multiple variables assigning to each other etc.

A constant named DoesNotExist doesn’t actually tell us anything. It doesn’t even indicate that it’s a boolean.

Sorry for the delay. The ValidateEnvironment workflow highlight above is using the DoesNoteExist read-only variable to initialize the non-read-only variable directoryExists. Also, I wasn’t stating that the read-only variable cannot be used for initialization as fact, but only that it cannot in my current configuration.

Somewhere you’ve designated directoryExists as read only. Use the universal search to see if maybe you accidentally defined that variable more than once. If not, try deleting and redoing the Assign activity. Sometimes it gets “stuck” and you have to redo it.

I performed the following, but I am still encountering the mentioned output. Also, just a FYI, I am using UiStudio 2022.4.5, RE Framework version 22.4.11.

  • Did a search on the local variable to examine if the same name was used in multiple scopes with one being read only. I found none.
  • I deleted the assign activity, and recreated it.
  • I deleted the entire workflow file, and created a new one in the same project.
  • I created a new project w/ the mentioned RE Framework template.
  • I created a new process project. When the read only variable is not defined, the process executes. As soon as the read only variable is defined, the mentioned output occurs.

I created a read-only in my current project, and even gave it a value in Default, and it worked fine.

What Arguments are you using, since these are invoked files? The error may be related to the Arguments, that’s why it always appears to be the first activity that faults.


  • For the existing project, that utilized the RE Framework, the config dictionary object (Dictionary<string,object>) is passed in as an argument

  • For a new test project, that utilizes the RE Framework, there are no arguments.

  • For the project that is just a process, there are no arguments.


  • For the question on if the project is in a zip file, no we are not opening these files in a zip file. We store our code in source control (DevOps) and pull it down for modifications.

Based on above, it doesn’t matter if the project is using the RE Framework or not. A simple project (Compatibility = Windows; Language = VB) with a single process will produce the exception for me. I did a few more tests.

  • When the project was first created, I added a sequence to the main process. I defined a read only variable in the scope of the sequence, and ran the project. No exception was thrown.
  • I added a single WriteLine activity, with the text “test”, into the sequence. No exception was thrown.
  • I then added an assign activity after the WriteLine activity. I tried to assign a string variable the value of “test”. The exception was thrown.

I captured a few more, possibly relevant snippets.

Exception Data



(Also, as a recap, this is for VB - Windows Compatibility)

I found that if only string constants are used in the process, this issue does not popup. As soon as a Boolean constant or Int32 constant is defined, the error is trigger.

An additional test, and snip.

  1. I added a sequence to a blank process. On the variables panel, I created a ReadOnly Boolean variable with a value of True.
  2. I ran the process, no issues.
  3. I added a WriteLine Activity with “test” for text
  4. I ran the process, no issues.
  5. I added a new variable of type Int32 with no default value that is not ReadOnly to the variables panel.
  6. I ran the process, no issues.
  7. I added an assign activity to the sequence. In the assign sequence, I assign the Non-ReadOnly variable the number 1.
  8. I ran the process, the error is thrown
  9. I changed the ReadOnly Boolean variable in step 1 to type String, and gave it text, “This is readonly”.
  10. I ran the process, no issues.

Step 8

Step 10 - (Notice the output panel)

After a meeting with a tech, the solution was to update to the latest version of UiStudio.

As mentioned above, I was running UiStudio v2022.4.5.

I upgraded to UiStudio v2022.10.4.
(which has upgraded dependencies on new processes, such as UiPath.System.Activities 22.10.4)

Somewhere along the lines, a bug fix must have been put in place.

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