Complex lambda expression

Hello,

I have a lambda that i tried to improve :

When i add that part of code : And w.Value.ToString.Equals(TestInput)

I have an exception :

But no problem if i Hardcode the Contains(“XXXXXX”), so i suppose i can’t use variable in lambda ?

Someone know how fix it ?

I have a few questions:
Where are you placing this Lambda? Assign activity or somewhere else?
The error says it is a Write Line. What is inside the Write Line activity?

Your lambda looks ok to me, so it must depend on how you are using it.

that is the write lin :

image

But in debug the exception source look like in the assign :

And if i replace the variable testInput by its value : “Foo” there is no exception

@Zoul Can you delete that variable and try creating again and check

Same thing :

complete stacktrace :

19.12.0-beta.61+Branch.release-v2019.12.0.Sha.c5ef64a84dd6be2c140a75da8fd036824faab942

Source: Write Line

Message: Activity ‘1.3: VisualBasicValue’ cannot access this public location reference because it is only valid for activity ‘1.9: VisualBasicValue<IEnumerable>’. Only the activity which obtained the public location reference is allowed to use it.

Exception Type: System.InvalidOperationException

RemoteException wrapping System.InvalidOperationException: Activity ‘1.3: VisualBasicValue’ cannot access this public location reference because it is only valid for activity ‘1.9: VisualBasicValue<IEnumerable>’. Only the activity which obtained the public location reference is allowed to use it.
at System.Activities.InlinedLocationReference.ValidateAccessor(ActivityContext context)
at System.Activities.InlinedLocationReference.GetLocationForRead(ActivityContext context)
at System.Activities.ActivityContext.GetValueCore[T](LocationReference locationReference)
at System.Activities.ActivityContext.GetValue[T](LocationReference locationReference)
at lambda_method(Closure , KeyValuePair2 ) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Linq.Enumerable.Count[TSource](IEnumerable1 source) 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, IDictionary`2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

if the error comes only at the write line, then just try things slower, use a regular IF condition and two write lines, so you can see where the error is…

@Zoul Are you using a variable of type Enumerable or of Type IEnumerable?

Hello @supermanPunch, I use :

IEnumerable dicoOut3
Testinput String

Thank your for your help

BR

@Zoul Can you change it into Array of String

2 Likes

From what I remember last time I tried to do this, the problem isn’t the Lambda itself, it’s just that standard LINQ (what’s powering the Where statement) doesn’t work with variables because the query is precompiled

Take a look at SO

SupermanPunch, Well done Sir ! Its works, big thx!

Do you know what was the problem ?

@JCaravaca, @bcorrea, @ClaytonM Thank you for your very appreciated help

@Zoul Using IEnumerable as a Type is wrong I guess, Since I in IEnumerable stands for Interface, and interface can’t be used as a Data, I guess this was the reason, Even I had encountered that problem before :sweat_smile:

1 Like

Ok i understand, thank you very much for your involvement <3

1 Like

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