Serialization Issue with Windows Workflow Foundation and Sharepoint Workflow

Problem

You are receiving the error similar to the one below when attempting to execute a SharePoint WWF workflow. 

======================================================================================

11/19/2009 10:52:19.18     w3wp.exe (0x17FC)                          0x157C    Windows SharePoint Services      Workflow Infrastructure          88xr    Unexpected    WinWF Internal Error, terminating workflow Id# 86a35560-7bc3-4841-8a81-d8180d9b6f5c   

11/19/2009 10:52:19.18     w3wp.exe (0x17FC)                          0x157C    Windows SharePoint Services      Workflow Infrastructure          98d4    Unexpected    System.Workflow.Runtime.Hosting.PersistenceException: Type ‘Microsoft.SharePoint.SPWeb’ in Assembly ‘Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ is not marked as serializable. —> System.Runtime.Serialization.SerializationException: Type ‘Microsoft.SharePoint.SPWeb’ in Assembly ‘Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ is not marked as serializable.    at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)    at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)    at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()    at System.Runtime.Serialization.Formatters.B…   

11/19/2009 10:52:19.18*    w3wp.exe (0x17FC)                          0x157C    Windows SharePoint Services      Workflow Infrastructure          98d4    Unexpected    …inary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)    at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)    at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)    at System.Runtime.Serializati…   

11/19/2009 10:52:19.18*    w3wp.exe (0x17FC)                          0x157C    Windows SharePoint Services      Workflow Infrastructure          98d4    Unexpected    …on.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)    at System.Workflow.ComponentModel.Activity.Save(Stream stream, IFormatter formatter)    at System.Workflow.ComponentModel.Activity.Save(Stream stream)    at System.Workflow.Runtime.Hosting.WorkflowPersistenceService.GetDefaultSerializedForm(Activity activity)    at Microsoft.SharePoint.Workflow.SPWinOePersistenceService.SaveWorkflowInstanceState(Activity instanceState, Boolean unlock)    at System.Workflow.Runtime.WorkflowExecutor.Persist(Activity dynamicActivity, Boolean unlock, Boolean needsCompensation)    — End of inner exception stack trace —    at System.Workflow.Runtime.WorkflowExecutor.Persist(Activity dynamicActivity, Boolean unlock, Boolean needsCompensation)    at System.Workf…   

Explanation

This error occurs when you have complex member objects in your C# or VB code that SharePoint can’t serialize.  These objects, typically something like SPWeb or SPUser can’t be serialized so SharePoint throws this error, typically after first workflow task.

Solution

Do not create member (top level) variables in your workflow classes. For example, do not declare something like “SPWeb web = spWorkflowProperties.web”.  Instead retrieve this information within each method. 

In another example, I had attempted to create my own approvals class in one of my workflows that was a simple class that I had created with three properties.  SharePoint didn’t let the workflow run past the first task until I had marked the approvals class as Serializable.

 

[Serializable]
public class Approvals{

}

VN:F [1.9.1_1087]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.1_1087]
Rating: +1 (from 1 vote)

Popularity: 7% [?]

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

No Responses to “Serialization Issue with Windows Workflow Foundation and Sharepoint Workflow”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>