Empty String with Spaces in a Variable

studio
variable

#1

If i initialize empty string with spaces (5) to a string variable in Assign activity, it gives me below error.Is it not allowed programmatically or is it a bug?

image

This works

strEmpty= new String(" "c, 5)


#2

Not sure but bottom option is definitely better as it tells someone more clearly that you wanted 5 spaces. Not sure this is going to be top of the fixes list :stuck_out_tongue:


#3

I don’t want this to be fixed. Just wanted to know if it is allowed or not.

Nevermind, found the answer. Thanks.

strEmpty= " "c


#4

There’s always String.Space method, too.


#5

Thanks. I know this is a silly question, but wasted 30 minutes trying to figure out as there were no validation errors.

This one @andrzej.kniola ?

Microsoft.VisualBasic.Strings.Space(5)


#6

Yes, it’s that one.
You can also use Space(5), since it doesn’t collide.

If you look at the studio logs after trying to run, you’ll find something like this with the initial example:

15:28:23:357 => [ERROR] [UiPath.Workflow.Logging.StudioTraceListener] [7] System.Activities.InvalidWorkflowException: The workflow has validation errors. Review and resolve them first. ---> System.Activities.InvalidWorkflowException: The following errors were encountered while processing the workflow tree:
    'DynamicActivity': The private implementation of activity '1: DynamicActivity' has the following validation error:   Value for a required activity argument 'Value' was not supplied.
       at System.Activities.Validation.ActivityValidationServices.ThrowIfViolationsExist(IList`1 validationErrors, ExceptionReason reason)
       at System.Activities.WorkflowInspectionServices.CacheMetadata(Activity rootActivity, LocationReferenceEnvironment hostEnvironment)
       at UiPath.Workflow.ViewModels.MainViewModel.IsWorkflowValid()
       --- End of inner exception stack trace ---

This is because when serializing literal values, they’re put straight into the value:

<InArgument x:TypeArguments="x:String" xml:space="preserve">    </InArgument>
<InArgument x:TypeArguments="x:String">abcd</InArgument>

The xml:space="preserve" is added automatically. If you delete it, value will be treated as not present when you reopen workflow.
When testing further, with a string value of

<InArgument x:TypeArguments="x:String" xml:space="preserve">    a    </InArgument>

It works correctly (honoring whitespace as well). So it seems it’s just when there’s only whitespace as literal value it has issues. Possibly interpreter at some point doesn’t honor preserve attribute correctly.


#7

Good catch @vvaidya, I tried to replicate and noticed that the exception is thrown only at runtime, when you click on Validate button it says no errors though and not blue exclamation.

Thanks to @vvaidya and @andrzej.kniola, I will keep this in mind!


#8

as per my understanding, it must be bug @vvaidya. because it does not show any blue mark/symbol on assign activity and even we validate the workflow it shows “No validation errors found” in your file.
Please make me correct if I’ve told wrong.

Kind Regards,
Pankaj


#9

Super! Thanks.