Sunday, September 13, 2009

SharePoint Custom Workflow Error (related to Serialization): WinWF Internal Error, terminating workflow

I created a custom workflow using VS 2008 for MOSS 2007.
In my SP site, I created a custom list CONTACTS with following columns:
Region - Single Line Text
Dept1 - Person Group
Dept2 - Person Group
Dept3 - Person Group

In this workflow, I need to retrieve users from CONTACTS list and create tasks for the users included within the groups associated to Dept columns.
I created custom workflow and ran it by associating to another list.
I got following error:
"WinWF Internal Error, terminating workflow Id# d4a5785f-22bf-42e8-bfca-d561bdb44ed7 System.Workflow.Runtime.Hosting.PersistenceException: Type 'Microsoft.SharePoint.SPUserCollection' 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.SPUserCollection' 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.Seri... ...alization.Formatters.Binary.WriteObjectInfo.InitSerialize(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.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) at System.Workflow.ComponentModel.Activity.Save(Stream stream, IFormatter formatter) at System.Workflow.Runtime.Hosting.WorkflowPers... Workflow Infrastructure 98d4 Unexpected ...istenceService.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.Workflow.Runtime.WorkflowExecutor.ProtectedPersist(Boolean unlock)"

What I understood from above exception in the SharePoint Logs:
The exception raised by WF is because of SPUserCollection object is not marked as serializable.
I made following changes to my code:
a. Marked my custom workflow class as serializable as all the objects within WF must be serializable. I did this by placing the attribute on top of the class as below:
[Serializable()]
public partial class SampleWorkflow : SequentialWorkflowActivity
{
}
b. Removed declaration of SPUserCollection objects as these obj are not serializable. To store user information for each department, i created separate hashtable and stored the data while retrieving the user information, instead of storing SPUser or SPUserCollection objects.

Reference Blog Posts, which helped me in solving this problem:
http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/01cde268-5148-4ff7-847e-1d03803c91c2
http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/9bd91cba-558c-456a-8f3c-e0e829145ec6/
http://blogs.msdn.com/sharepoint/archive/2006/11/28/developing-workflows-in-vs-part-5-code-your-workflow.aspx

Friday, September 4, 2009

Building ASP.NET DatePicker

Following link has simple way of creating a datepicker in ASPX pages.
http://www.codedigest.com/Articles/ASPNET/247_DatePicker_Control_in_ASPNet.aspx

Debugging tips for SharePoint

Today, I came across with very good post regarding debugging tips for SharePoint.
http://blog.thekid.me.uk/archive/2007/07/25/debugging-tips-for-sharepoint-and-wss-exceptions.aspx
Most of the tips you may know already but this list has collection of tips.
Enjoy debugging.