none
Infopath xsd and sharepoint workflow serialization problem

    Question

  • 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
    Tuesday, January 23, 2007 9:46 PM

Answers

  • 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.
    Friday, February 16, 2007 9:36 PM

All replies

  • 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

    Thursday, February 08, 2007 7:33 AM
  • 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

    Thursday, February 08, 2007 5:13 PM
  • 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

    Monday, February 12, 2007 6:11 PM
  • 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!
    Thursday, February 15, 2007 11:55 AM
  • 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.
    Friday, February 16, 2007 9:36 PM
  • this was the point, thanks a lot!!
    Monday, February 19, 2007 3:38 PM
  • Great thread guys, thanks very much for posting this. This definately helped me resolve the same problem I had as well. After doing a little testing to see what exactly works and coming up with what you found, I was also wondering why it wasn't doing that before, when I was just transporting around XML. I then realized that my private workflow objects were being serialized! I figured this was using XML serialization until I looked a little closer at the log files.

     

    Going along with adding the NonSerialized attribute to the schema-generated file, what I also found effective was to place the attribute on my private member variables representing the infopath form schema-generated objects.

     

    For instance, my association/initiation form I was reading through workflowProperties.InitiationData (code is in C#, sorry, i hope you get the point though). The schema-generated class is "SubmitExpenses". I created a read-only property for this

     

     

    Code Snippet

    [System.NonSerialized]
    private SubmitExpenses _expenses = null;


    public SubmitExpenses expenses
    {
     get
     {
      if (_expenses == null)
      {
       XmlSerializer xs = new XmlSerializer(typeof(SubmitExpenses));
       XmlTextReader xtr = new XmlTextReader(new StringReader(workflowProperties.InitiationData));
       _expenses = (SubmitExpenses)xs.Deserialize(xtr);
      }
      return _expenses;
     }
    }

     

    I found that when I added the NonSerialized attribute to the private member, my Dehydration issues went away.

     

    Tuesday, September 25, 2007 2:04 PM
  • Hi guys,
    I have a similar exception. That drives me mad.
    I don't have any Initiation and association forms. I only have my own aspx task edit form
    developed by vs 2005.
    Can anyone help me for the problem?

    Thanks!


    Monday, April 28, 2008 5:18 PM
  • Finally,  I found the solution from the pitfall:
    http://blogs.msdn.com/sharepoint/archive/2006/11/28/developing-workflows-in-vs-part-5-code-your-workflow.aspx

    Monday, April 28, 2008 6:12 PM
  • Thanks for the answer, baswegan!  It seems to work for me so far!
    Monday, July 28, 2008 7:35 PM
  • Can you tell me what the solution was Auther?  I've been looking everywhere, and can't find anything!  Really appreciate it.  Thanks :)
    Friday, October 03, 2008 6:10 PM
  •  In case you're still looking for the answers.

    Pitfall: Re-using non-serializable SharePoint objects after rehydration
    Many non-workflow specific SharePoint objects, like SPListItem, are not serializable, so when the workflow dehydrates, these items become invalid.  So if you try to use them when the workflow wakes up, you will get an error.  To avoid this, refetch items if you’re using them after a workflow rehydrates. 

    This may be the reason that causes you problems. Check it out whether or not you have class variables with type of SPUser or SPWeb, etc.
    Tuesday, October 14, 2008 7:43 PM