Wednesday, 20 February 2008

More workflow issues and resolutions

What I wanted to do today is run through is wrap up my series of workflow posts, by running through some of the issues I hit during development. If you're into workflow, you may have seen Rob Bogue's excellent 10 issues (and resolutions) for SharePoint+Workflow - this post is something of an extension to Rob's. It probably makes for rather dry reading, but will hopefully be useful to those Googling for specific problems.

  1. Issue:- Error message "System.Xml.XmlAttribute is not serializable" shown in workflow history list and workflow will complete before it is supposed to. In SharePoint log, will see "End of Stream encountered before parsing was completed” error.

    More information:- This is caused by trying to store a class which cannot be serialized as a member (e.g. private variable) of the workflow class. Furthermore, I also encountered this error when storing the class which represents the InfoPath form - interestingly this class will always definitely be serializable, but the error was happening nevertheless.

    Resolution:- Mark member as NonSerializable (so workflow does not attempt to serialize the class, and copy primitive data (e.g. strings, dates etc.) out of form class and into individual field-level variables. It might also be possible to mark the ‘AnyAttr’ member of the generated class as NonSerializable instead.

  2. Issue:- InfoPath forms do not get updated upon solution deployment - changes are not reflected.

    More information:- This happened when I initially started development. I noticed that if I separately deactivated/uninstalled the workflow Feature, the InfoPath forms would then update successfully. This pointed me to an issue with the PostBuildActions.bat script.

    Resolution:- Modify PostBuildActions.bat to use the -force parameter when deactivating/uninstalling the Feature.

  3. Issue:- Error message "The e-mail message cannot be sent. Make sure the outgoing e-mail settings for the server are configured correctly." is shown in the workflow history list. E-mail configuration is known to be good (e.g. alerts are working).

    More information:- I suspect there are several reasons why this may happen, but for me the problem was how I was using the SendEmail activity. When I was setting properties on the SendEmail variable the workflow designer had added to my class for me, I had the error.

    Resolution:- The best way I found to deal with this was to set properties on the object which is passed to the SendEmail's 'MethodInvoking' code. You'll need to cast to SendEmail before you can do this.

  4. Issue:- The TaskID for a CreateTask activity does not get populated. The value defaults to -1 instead.

    More information:- This will be an issue in several scenarios, one example is when building the URL for a task (e.g. to include in an e-mail to a user) with code similar to Paul Hunt's code shown at

    Resolution:- The TaskID will only be populated if there is a place to store the value. Ensure the TaskID property on your CreateTask activity is bound to a variable.

  5. Issue:- Error message "Correlation value on declaration 'x' is already initialized" message shown in SharePoint log when a task executes for the second time in a workflow.

    More information:- This scenario can happen when a CreateTask runs for a 2nd time due to an approver rejecting something in the workflow.

    Resolution:- The 'OwnerActivtyName' of the task's correlation token is incorrectly set. In a state-machine workflow, it should refer to the particular state, not the overall workflow.

  6. Issue:- Unexplained errors when some part of an otherwise functioning workflow is commented out in the designer (e.g. 'Failed on start').

    More information:- You've commented out one or more activities in your workflow (using right-click > Disable), but observe strange behaviour and/or errors. This is actually because, in contrast to commenting out source code, the code is actually still compiled into the assembly. Hence if there is an error with say, a correlation token being incorrectly set, this will still cause a problem in your workflow.

    Resolution:- Fix problem or remove faulting activity/activities completely from workflow.

For completeness, some other common issues which are well documented in other sources are:

  • 'Failed on start' - this often caused by a problem loading the workflow assembly. Check the PostBuildActions.bat script (or whatever you are using) has properly deployed the assembly to the GAC, and all the assembly attributes (version, public key token etc.) match those specifed in the Feature files.
  • 'SPException: This task is currently locked by a running workflow and cannot be edited' message. This is documented by Rob Bogue and others, but I'd also add this can occur as a knock-on effect of another problem. If an earlier exception has occurred whilst trying to process a task, the workflow will have locked the task on the first run, meaning that subsequent attempts by a user to respond to the task will result in this error. Other than fixing the problem at source, I haven't found an elegant way of dealing with this.

So hopefully that's of some use to workflow developers. If you haven't seen it already, there's a lot more goodness (sample code, tips and tricks etc.) in my workflow resources pack from the workflow deep-dive presentation I did at the UK SharePoint user group earlier this year.

Happy coding!


Javier said...

Hi Chris, you have a great blog! Congratulations.
I have a question for you, i'm having problems with the populating of the listitemid on the methodinvoking of the creating task. The create task activity is inside a while and the value is -1.
I don't understant what is happening in other task it worked.
Do you have any suggestion?

Chris O'Brien said...


This looks like the issue I discuss in issue 4 in the list above (but for a different property). I'd suggest checking the ListItemID property of the task is bound to a variable.



Anonymous said...

Hi Chris,

I came across your blog a number of times while trying to get rid of one issue or the other. You indeed have a great work going on. Thanks a lot for all your help.


Anonymous said...

You have a great blog..!
My problem is I have built a complex custom workflow with code behind in the Association form. Every thing worked perfect until i made some changes such as modified code behind the Association form and added a private method.
Now i see a error stating
System.Xml.XmlAttribute is not serializable in workflow history log
Please help..!


Chris O'Brien said...


This looks exactly like the issue I discuss in issue 1. I think your new code is probably storing something as a private variable which can't be serialized.

As a test, what happens if you rollback your code - does the problem disappear?



Anonymous said...


I am having the following problem:
I have a workflow WF1, on list:A that creates several tasks in tasklist:B in replicator. My tasks get created fine, and the workflow completes. Now have a 2nd workflow WF2, that gets started when a new item is added in the tasklist:B. the problem is WF2 never starts. Apparently the tasks created by WF1 are using content type "Workflow Task", which cannot see association with any workflow whatsoever. But if I myself create a task in the tasklist:B on content type "Task", WF2 starts properly and executes. Can you please help? I have tried several ways, but could not strike a solution!!

Chris O'Brien said...


Sorry, I'm afraid I can't think of any answers to that one right now :-(

Best of luck,


Anonymous said...

Nice list of workflow issue you have listed.

Recently I came across a weird workflow issue. Issue happened when reassigning the workflow task to some other user.

And eventually I found the resolution/workaround that is documented here.

Rahul Vartak said...

very Nice blog chris..Good initiative to note down all issues faced..

Heres a list of steps i documented while having hands on on SharePoint 2007 State machine workflows.

Hope this helps..:)

Anonymous said...

Hi can you share your experience please
I have an issue on SendEmail activity. The workflow receives email from outlook, creates announcement list item and sends email to recipients.
I used the following options one at a time:
//The following are outgoing email properties
option 1:
_emailbody = "My email body 01";
_emailsubject = "My email subject 01";
_emailto = "";
_emailcc = "";
_EmailBCC = "";
_EmailFrom = "";

option 2:
sendEmail1.CC = "";
sendEmail1.Subject = "My email subject 01";
sendEmail1.Body = "My email body 01";
sendEmail1.To = "";
option 3:
SPUtility.SendEmail(workflowProperties.Web, true, false, " ", "Subject 01", " My email body 01");

The first time I send email from outlook to a new workflow project the workflow works fine and receives and sends email correctly. Then when I change the outgoing email subject or body and run the workflow, it sends the original subject and body. The workflow sends the same email subject and email body over and over when list item is created from email received from outlook.
When the item is created from browser, the workflow works fine. I used the correct correlation token.
Please can you forward your suggestion please?

Chris O'Brien said...


I'm not sure why that would happen - could it be that the workflow is taking different paths depending on how the item was added?

Also, if the e-mail sent by the workflow should use values from the list item being added, shouldn't you be using these values (i.e. from workflowProperties.Item) rather than hardcoded strings?



Anonymous said...

Hey Chris thanks for nice blog. I have a problem in my workflow where code from my CreateTaskWithContentType gets executes completely and as soon as it gets out it the workflow stoopedd with message "Error occured" I am not able to recognize the error. Please help me in that.- AJit

Chris O'Brien said...


Anything more detailed in the ULS logs at all?