Getting Newtonsoft serializable error while using wait for form task and resume activity

Hi Team,

I am creating a form, adding form object to collection and running a loop on collection-list and getting Newtonsoft serializable error while using wait for form task and resume activity…i have checked wait for form task activity is working fine without loop can anyone help me to resolve this ?

System.Exception: Types from namespace Newtonsoft.Json.Linq (including JObject) are not serializable. Could not serialize type System.Activities.Variable`1+VariableLocation[[Newtonsoft.Json.Linq.JToken, Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed]] —>

Thanks in Advance.

Regards,
Deepak

Some datatypes cannot be serialized, which is a necessary step for it to wait for the form task. You have to scope your variables properly.

Also, you shouldn’t use a loop when using the Wait activity. It will create the form task and then Wait on the first iteration of the loop, then resume after the action is completed and then do the next item in the loop.

1 Like

@postwick I have 10 items and i am creating all 10 forms in one go and adding the form task object one by one in list using add to collection activity. After adding all data , i am running a loopto check the user action and basis on that i am adding data to queue.

Hi @deepakchawla

So your job will running > resume > running and so one until users validate the 10 actions, right? is it a expected behavior?

As mentioned by postwick, you need to scope your variables properly otherwise they will be break your flow if they aren’t the supported type as mentioned here is Best Practices section:

What you want to do is a dispatcher that processes the 10 items and creates queue items. Then those queue items trigger multiple jobs of a linear process that picks up a queue item, creates the form action and waits. Then you have one waiting job per item. The linear process, after resuming, would then do the rest of your steps for the item (like creating the queue item).

The loop the way you have it will not continue to the second item until the first item’s action is completed. And you don’t check the user action on a loop. The system does that for you. That’s the point to the Wait activity. It suspends the job until the action is completed, and once the action is completed automatically resumes the job.

@postwick I am creating a 10 form before adding data to queue and adding form task object in the collection. After that running a loop over list and basis user action we need to add data to queue

i tried changing scope of long running variable but facing same issue …How to resolve newton error ?

Did you ever successfully resolve this? I am facing EXACTLY the same problem and it’s driving me nuts!

@tclukay Yes, I have resolved this error. Please move all the wait for form task variables to main xaml

Thanks!! I’ll give that a try! :sunny:

… and sadly, if I’m understanding your response correctly, it has to be something else. ALL my code is inside the Mainline routine, and ALL the variables in use are scoped to Main. So something else is going on here. But thanks for the quick suggestion.

Scoping your variables to Main is the problem. That means when it suspends it has to serialize all the variables. You have to make sure non-serializable variables are NOT in the scope that the Wait activity is in. If you scope everything to Main then they’re all in every scope.

Here is another thread on this topic, and a reply where I fixed someone’s code to resolve this issue.