Issue while filtering Queue items based on Specific Content

I am trying to filter queue items based on specific content present in it.

After using below expression, ienFilteredQueueItems.Count is working fine:

ienFilteredQueueItems = ienProcessedQueueItems.AsEnumerable.Where(Function(x) x.SpecificContent(“Field1”).ToString.Equals(“Test”))

But after using below expression, ienFilteredQueueItems.Count throws error. Only difference is now I am comparing field value with a variable strCompareValue

ienFilteredQueueItems = ienProcessedQueueItems.AsEnumerable.Where(Function(x) x.SpecificContent(“Field1”).ToString.Equals(strCompareValue))

Error: An ActivityContext can only be accessed within the scope of the function it was passed into.
Object name: ‘System.Activities.CodeActivityContext’.

Could you please help, what’s going on here? I can not share any workflow. But steps to reproduce are as below:

  1. Use Get queue items to get few queue items
  2. Filter with above expressions for picking few queue items which have some specific field value in it
  3. Log the count of final filtered queue item
  4. Log activity throws error when I am comparing the queue items field with a string variable instead of a direct string value.

@SumitTyagi1810

Can you try like this

ienFilteredQueueItems.ToArray().Count

Or instead of ienfilteredqueueitems…try changing that to array and add .ToArray there

Cheers

@Anil_G Thanks for replying.
I actually do not need the count. It was just to state that ienFilteredQueueItems is not getting any results on using the second expression. Even if just use the For each loop on ienFilteredQueueItems , logging of item.Reference is also throwing the same error.

@SumitTyagi1810

Basically for loop or those needs array and no IEnum I feel…Because I saw this error in a similar situation and it got resolved by adding toarray or tolist

So try that in your for loop as well try casting it to toarray and check then if you are able to get the reference

Try loop on ienFilteredQueueItems.ToArray()

Hope this helps

cheers

Hi @SumitTyagi1810 ,

Could you let us know what was provided in the Log Message Activity ?

ienFilteredQueueItems.Count.ToString

If the error is due to Ienum, then it should not even work in the first case. But I will try it as well.

@SumitTyagi1810

I am not confirming or have a reason of the error…but as per the experience I had this solved the issue and I could move on from there

cheers

Still getting error when I tried to for loop with ienFilteredQueueItems.ToArray()

Hi @SumitTyagi1810 ,

Could you debug it? Add a breakpoint before using .Count to see you are getting any queueItems after filtering using 2nd expression.

ienFilteredQueue item value in Debug Mode is: Enumerable.WhereListIterator { !ObjectDisposedException … }

Object DisposedException for the input variable

I’m still working on this, this seems a bug for now because when you pass string value expression returns IEnumerable of QueueItem and when using variable then it throws an exception that’s why .Count is not working.

Yes, that’s the main problem. Any resolution will be helpful.

Meanwhile I am going through alternate approach for converting QueueItems to DT and then using it for further process.

@SumitTyagi1810

I did try this with variable…And it did print without issue…Can you remove AsEnumerable or try as below

quls.Where(function(x) x.SpecificContent("Test1").ToString.Contains(str)).Count

did try the other as well and I am not getting any error

quls.AsEnumerable.Where(function(x) x.SpecificContent("Test1").ToString.Contains(str)).Count

Try modifying the systems package and see if the issue is fixed.

Else delete the system package from .nuget and reopen the project

cheers

Hi,

Found the solution, you can use Invoke code instead of assign for filtering the queueItems.
Refer the image below:

Use in arguments: str variable to filter and IEnumerable of type QueueItem to filter on.
Use out argument: IEnumerable of type QueueItem to store filtered queue Items.
Paste code: out_queue = in_queue.Where(Function(x) x.SpecificContent(“yourFieldName”).ToString.Contains(in_str))

Please mark as solution if it helps.

typically we do see this, when within the LINQ processing something is failling. (will also happen, when executed within an invoke code activity).

As we do have an access to a Dictionary Key within the Specific Content, you can evaluate if all items do have the key. Use immediate panel and the following Statement:

Check 1: we check that it is not null
ienProcessedQueueItems

Check 2: all items do not have the key

ienProcessedQueueItems.Where(Function (x) Not x.SpecificContent.ContainsKey("Field1")).ToArray

Based on the results from this checks we can decided next further analysis when it is still needed