Infopath xsd and sharepoint workflow serialization problem

I have a simple form that I am using for Association in my workflow. The form works fine and I can associate my workflow to the document library. The problem comes in when I try to use the form data in my workflow. I am using the following code to import the form data into the AssociationData class.

I exported the form code, ran "xsd.exe /c /l:vb mychema.xsd" which generated the appropriate class. I am using the following code to generate my class from the form data (extra lines removed for readability):

Public Class PurchaseReqWorkflow
Public workflowProperties As SPWorkflowActivationProperties = New Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties
Public assocData As New AssociationData()

Private Sub codeActivity1_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim serializer As New XmlSerializer(associationData.GetType)
Dim reader As New XmlTextReader(New System.IO.StringReader(workflowProperties.AssociationData))
assocData = CType(serializer.Deserialize(reader), AssociationData)


The code executes fine and the assocData object is populated with correct values (viewed when debugging). The problem comes in when the workflow attempts to dehydrate and I get the following error in my sharepoint logs:

DehydrateInstance: System.Runtime.Serialization.SerializationException: End of Stream encountered before parsing was completed. at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run() at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream) at System.Workflow.ComponentModel.Activity.Load(Stream stream,...
01/23/2007 15:42:16.30* w3wp.exe (0x1318) 0x0268 Windows SharePoint Services Workflow Infrastructure 72eo Unexpected ... Activity outerActivity, IFormatter formatter) at System.Workflow.ComponentModel.Activity.Load(Stream stream, Activity outerActivity) at System.Workflow.Runtime.Hosting.WorkflowPersistenceService.RestoreFromDefaultSerializedForm(Byte[] activityBytes, Activity outerActivity) at Microsoft.SharePoint.Workflow.SPWinOePersistenceService.LoadWorkflowInstanceState(Guid instanceId) at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance) at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext context, WorkflowInstance workflowInstance) at System.Workflow.Runtime.WorkflowRuntime.GetWorkflow(Guid instanceId) at Microsoft.SharePoint.Workflow.SPWinO...
...eHostServices.DehydrateInstance(SPWorkflowInstance workflow)
WinWF Internal Error, terminating workflow Id# 993849ac-f594-423b-be45-abfae4290112

Now, what seems really odd about this is that if I comment out this line "assocData = CType(serializer.Deserialize(reader), AssociationData)", the workflow properly (de)hydrates. Since this is an xsd generated class that should be serializable, I am starting to get frustrated. Any help you can provide would be greatly appreciated. Thanks.

Brad Aswegan

[3817 byte] By [baswegan] at [2008-2-11]
# 1

I encountered a very similar problem. But one thing is different is that even I comment out the line of Deserialize() the workflow is still not working. But finally, when I find that the problem is come from the code of writing eventlog. After comment out the lines, the workflow works. But I still don't know why it is the problem.

Wo

CheungTinWo at 2007-9-5 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Workflow...
# 2

Hi Brad,

I just encountered this issue when I moved a second task into an IfElseBranchActivity. The workflow has two tasks, each with their own edit task form and it was working correctly, but then I added an If/Else and moved the second task into the If branch and now I'm getting the SerializationException. So far I haven't been able to find the offending code. Have you learned anything about the error?

Thanks

-Cynthia

cksturton at 2007-9-5 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Workflow...
# 3

It turns out I am getting this error as a result of using an invokeWebService activity. I still haven't been able to figure out what I'm doing wrong though. The web service gets invoked correctly and the next task gets created, but the workflow can't dehydrate correctly after creating the task. Have you had any luck?

Thanks,

Cynthia

cksturton at 2007-9-5 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Workflow...
# 4
Hi baswegan and ohters
I have nearly the same Problem. When I Start my Workflow , everthing is fine. The workflaw takes the IP-Initiaton-Form's Data creates a Task with a custom-IP-Form and wants to wait on Task-Chaned Event. Thenthe Workflow gets dehydrated and i get DehydrateInstance(SPWorkflowInstance workflow) - Error. I'm getting mad about this. I've another Workflow with nearly the same construction and thisone works fine, but mine is crashing and I can't fine the reaseon.
Did you find any solution to your problem or a reason why this error occures?
would be extremly happy for any answer to this problem, thx!
AndreasSchnegg at 2007-9-5 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Workflow...
# 5
Yes, I found a solution.

In the automatically generated class, I had to mark the following variable and non-serialized and everything was happy again. I think it has something to do with the "lang" element in an infopath template, I remember you used to have to programatically remove it before doing certain operations on infopath documents. I can't for the life of me figure out why infopath doesn't conform to xml standards, but it doesn't.

<NonSerialized()> Private anyAttrField() As System.Xml.XmlAttribute

Hope this helps.

baswegan at 2007-9-5 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Workflow...
# 6
this was the point, thanks a lot!!
AndreasSchnegg at 2007-9-5 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Workflow...

SharePoint Products and Technologies

Site Classified