Tuesday, May 6, 2014

Tip: Workflow Serialization Issue

In Windows Workflow 4.5, serialization of a long running process saves the workflow states (variables' value) and some other information into the database. However it's important to consider carefully the type of objects that the workflow can save. object such as EntitySet and EttityRef of LINQ2SQL by default do not support serialization into database. When try to save such objects into the database, error will be thrown by the workflow runtime:

Operation 'OperationName|IServiceContract' on service instance with identifier '899be275-01f7-45c7-a8d2-ee89595522cb' cannot be performed at this time. Please ensure that the operations are performed in the correct order and that the binding in use provides ordered delivery guarantees.

then

System.Runtime.Serialization.InvalidDataContractException: Type 'System.Data.Linq.EntitySet`1[WhateverObjectType]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute.

See the Microsoft .NET Framework documentation for other supported types. Microsoft does describe some of the thing about LINQ2SQL serialization at Serialization [LINQ to SQL]

We tend to pass in the LINQ2SQL object into the workflow, so one way to workaround the problem is to nullify the object before the WF goes into idle mode. Use the object as a parameter passing vehicle instead of using it to store workflow state.

No comments: