Error generating string that has double quotes

I am trying to create command text that i will be using in Invoke Powershell activity. In oreder to create command I need to have a string that has double quotes as well as single quotes.

Below is string that i created in assign activity.

“$commandtext = ‘’”"" + in_ExePath.Trim + “”" -file “”" + in_FilePath.Trim + “”"’’" + Environment.NewLine + “$commandtext > “”” + Path.Combine(Environment.CurrentDirectory, “Run.txt”) + “”"" + Environment.NewLine

But i am getting error while assign statement itself as under

RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure ,
ActivityContext )
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance,
Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment,
ActivityInstance activityInstance,
ActivityExecutor executor)
at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment,
ActivityInstance targetActivityInstance,
ActivityExecutor executor,
Object argumentValueOverride,
Location resultLocation,
Boolean skipFastPath)
at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument,
Int32 nextArgumentIndex,
ActivityExecutor executor,
IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides,
Location resultLocation,
Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor,
BookmarkManager bookmarkManager,
Location resultLocation)

What I dont get is how am i getting “Object reference not set to instance of object” error when I am simply trying to assign string to a string type variable.


1 Like

Hi @JDoshi,
If you want to use double quotes in side a string, you must use escape characters. For eg:

like “this contains \” character"

And note that object reference not set to an instance of an object error will occur when we use variables which are not initialized.
Make sure to initialize all variables.

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