views:

486

answers:

2

Here is the stack trace of exception I get when workflow is persisted .

System.Workflow.Runtime.Hosting.PersistenceException: Type 'System.Xml.XmlElement' in Assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. ---> System.Runtime.Serialization.SerializationException: Type 'System.Xml.XmlElement' in Assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 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.Binary.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.Serialization.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 System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService.SaveWorkflowInstanceState(Activity rootActivity, 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)

I have no Idea how and where to debug. Please help.

A: 

Are you using the SQL persister?

Icey
yes, I am using sqlpersistence service
ksa
A: 

The error message tells you right at the top:

'System.Xml.XmlElement' in Assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

When a workflow is persisted the WorkflowPersistenceService uses the binary serializer to dump all the data in the workflow. So everything in there must be either marked as non serializable or must be binary serializble. An XmlElement isn't so you must either store the data in some other way or not save it at all.

Maurice
But the trace doesnt specify any file in my code, how do I debug it?
ksa
That is because it isn't your code trowing the exception. But some of the data that is stored as part of the workflow is and you know the type is XmlElement. Now it is up to you to look in your code where you use XmlElement or something that uses XmlElement internally. That can sometimes be kind of hard but if a quick scan doesn't work I typically start marking properties and non serializable and removing activities until the problem disappears. That way you can track down the offending property.
Maurice
You are correct, here is what I think might be the problem, I am not sure though, I am calling a webservice whose return value is object of type XmlNode. I save this object in dependency property.I have [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)] added too. Is this be the cause? If i dont call the webservice, there is no error, and workflow is persisted.
ksa
XmlElement derives from XmlNode so it is very likely the cause. But as you cannot use the binary serialzer you need to make a choice. Either you do not save the XML when the workflow is persisted, possibly because you no longer need it. Or you convert the XML to some data format you can persist, a string being the easy choice but something else like a domain object would be fine too.
Maurice
I saved the webservice response in CLR property with NonSerializable attribute. It worked fine. Thanks again Maurice.
ksa