Showing posts with label SharePoint 2007 Workflow. Show all posts
Showing posts with label SharePoint 2007 Workflow. Show all posts

Friday, 18 September 2009

Fix For SharePoint 2007 Workflow - "WorkflowValidationFailedException: The workflow failed validation."

If your workflow fails and goes to a status of "Failed on Start (retrying)", and you have declarative rule conditions in your workflow (or RuleSets), it is likely that your workflow cannot be loaded due to a validation error like the one below:

Engine RunWorkflow: System.Workflow.ComponentModel.Compiler.WorkflowValidationFailedException: The workflow failed validation.

FULL EXCEPTION FROM ULS:
08/31/2009 11:54:56.68 w3wp.exe (0x10DC) 0x047C Windows SharePoint Services Workflow Infrastructure 936l High Engine RunWorkflow: System.Workflow.ComponentModel.Compiler.WorkflowValidationFailedException: The workflow failed validation. at System.Workflow.Runtime.WorkflowDefinitionDispenser.ValidateDefinition(Activity root, Boolean isNewType, ITypeProvider typeProvider) at System.Workflow.Runtime.WorkflowDefinitionDispenser.LoadRootActivity(Type workflowType, Boolean createDefinition, Boolean initForRuntime) at System.Workflow.Runtime.WorkflowDefinitionDispenser.GetRootActivity(Type workflowType, Boolean createNew, Boolean initForRuntime) at System.Workflow.Runtime.WorkflowRuntime.InitializeExecutor(Guid instanceId, CreationContext context, WorkflowExecutor executor, WorkflowInstance workflowInstance) at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext con... 08/31/2009 11:54:56.68* w3wp.exe (0x10DC) 0x047C Windows SharePoint Services Workflow Infrastructure 936l High ...text, WorkflowInstance workflowInstance) at System.Workflow.Runtime.WorkflowRuntime.GetWorkflowExecutor(Guid instanceId, CreationContext context) at System.Workflow.Runtime.WorkflowRuntime.InternalCreateWorkflow(CreationContext context, Guid instanceId) at System.Workflow.Runtime.WorkflowRuntime.CreateWorkflow(Type workflowType, Dictionary`2 namedArgumentValues, Guid instanceId) at Microsoft.SharePoint.Workflow.SPWinOeHostServices.Send(SPWinOeWorkflow winoeworkflow, SPWorkflowEvent e) at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(Guid trackingId, SPWorkflowHostService host, SPWorkflow workflow, Collection`1 events, TimeSpan timeOut)



The Fix:

As described in http://blog.hhebnes.no/?tag=/workflows, the fix is to:

Edit the Visual Studio project file (using notepad) and add the second line below:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Windows Workflow Foundation\v3.5\Workflow.Targets" />

Then reload the project and redeploy the wsp and everything will hopefully work. I suspect this might be an issue with WSPBuilder and the project it creates as it doesn't create .NET 3.5 projects by default.

Sunday, 14 June 2009

InvalidOperationException "The event receiver context for Workflow is invalid" Problems with onTaskChanged in a SharePoint Workflow

As also mentioned here:

http://thorprojects.com/blog/archive/2006/11/30/invalidoperationexception-quote-the-event-receiver-context-for-workflow-is-invalid-quote-problems-with-ontaskchanged-in-a-sharepoint-workflow.aspx

If your OnTaskChanged activity is failing and your SharePoint ULS logs are showing something like the following:

06/14/2009 16:50:22.30 w3wp.exe (0x1548) 0x0208 Windows SharePoint Services Workflow Infrastructure 72ev Medium Value cannot be null. 06/14/2009 16:50:24.12 w3wp.exe (0x1548) 0x0208 Windows SharePoint Services Workflow Infrastructure 72ev Medium Value cannot be null. 06/14/2009 16:50:24.40 w3wp.exe (0x1548) 0x0208 Windows SharePoint Services Workflow Infrastructure 72er Medium System.InvalidOperationException: The event receiver context for Workflow is invalid. at Microsoft.SharePoint.SPEventReceiverDefinition.ValidContext() at Microsoft.SharePoint.SPEventReceiverDefinition.ValidReceiverFields() at Microsoft.SharePoint.SPEventReceiverDefinition.GetSqlCommandToAddEventReceivers(IList`1 erds) at Microsoft.SharePoint.Workflow.SPWinOESubscriptionService.CommitNewSubscriptions(Transaction txn, IList`1 erds) 06/14/2009 16:50:24.41 w3wp.exe (0x1548) 0x0208 Windows SharePoint Services Workflow Infrastructure 72fe High Error in commiting pending workflow batch items: System.InvalidOperationException: The event receiver context for Workflow is invalid. at Microsoft.SharePoint.SPEventReceiverDefinition.ValidContext() at Microsoft.SharePoint.SPEventReceiverDefinition.ValidReceiverFields() at Microsoft.SharePoint.SPEventReceiverDefinition.GetSqlCommandToAddEventReceivers(IList`1 erds) at Microsoft.SharePoint.Workflow.SPWinOESubscriptionService.CommitNewSubscriptions(Transaction txn, IList`1 erds) at Microsoft.SharePoint.Workflow.SPPendingWorkBatch.ProcessWorkItemBatch(Transaction transaction, Work method, IList`1 workItemBatch) at Microsoft.SharePoint.Workflow.SPPendingWorkBatch.Commit(Transaction transaction, ICollection items) 06/14/2009 16:50:24.47 w3wp.exe (0x1548) 0x0208 Windows SharePoint Services Workflow Infrastructure 88xr Unexpected WinWF Internal Error, terminating workflow Id# 82d5bb47-18c9-4fa1-a730-121984a7b435

Then you have probably done the following:

  1. Not assigned a Task Id variable to your OnTaskChanged Handler
  2. Assigned the wrong Task Id variable to the OnTaskChanged Handler.
  3. A combination of 1 and 2

I had mistakenly bound my OnTask changed handler in a Parallel workflow to a new variable rather than the existing TaskId variable I set during the Create Task Handler (so the Task Ids didn't match, hence the exception).

Wednesday, 10 June 2009

Workaround - Contact Selector does not work in Browser-based InfoPath forms

While this blog hints otherwise, http://blogs.msdn.com/infopath/archive/2007/02/28/using-the-contact-selector-control.aspx, it is not possible to use the InfoPath Contact Selector control when hosting InfoPath forms in the browser.

To get around this issue, you can either:
  1. Move to ASP.NET Pages for your task form
  2. Use a dropdown instead in your InfoPath form. You can programmatically populate it as described here: http://www.bizsupportonline.net/infopath2007/programmatically-fill-populate-drop-down-list-box-infopath-2007.htm

Tuesday, 9 June 2009

SharePoint 2007 Workflow - Workflow Completes Prematurely without Error

A SharePoint Workflow I'm currently working on seemed to be particularly flakey when I introduced a DelayActivity to it. Several steps after the DelayActivity would be skipped with no apparent reason every 2nd or 3rd time I ran it. Unpredictable problems like this are notoriously hard to nail down - but I managed to find the cause.

Looking at the SharePoint Logs in the 12 Hive (e.g. in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS"), I found the following "Workflow Infrastructure" error with a severity of "Unexpected":

DehydrateInstance: System.Runtime.Serialization.SerializationException: End of Stream encountered before parsing was completed.

The following blog entry on the SharePoint Team Blog
http://blogs.msdn.com/sharepoint/archive/2006/11/28/developing-workflows-in-vs-part-5-code-your-workflow.aspx

Gave the following possible reasons for a workflow failing in this way:

1. Pitfall: Re-using non-serializable SharePoint objects after rehydrationMany 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.

2. Pitfall: Forgetting to make custom classes serializableWhen creating your own class in a workflow, don’t forget to add the “Serializable” attribute to the class. If you don’t do this and declare a variable of that class in the workflow’s scope, the workflow will fail when it tries to go to sleep and serialize the class. If you notice that the workflow “completes” when it isn’t supposed to, this may be the culprit.

I marked my custom classes with the [Serializable] attribute and the problems all disappeared.

[UPDATE - 9 Jun 2009]

As discussed in this post:
http://social.msdn.microsoft.com/forums/en-US/sharepointworkflow/thread/5bf2ed45-da4b-4c64-9ea3-aa6974fe2ab7/

I also had to tag my member variables for any InfoPath Forms schema-generated objects (even though they are private, they are still serialized) with a [System.NonSerialized] flag. I created a wrapper for my form instead:





[System.NonSerialized]
private InitiationForm _initiationForm = default(InitiationForm);

//Property for all access to the InfoPath form wrapper class
public InitiationForm InitiationForm
{
get
{
if (_initiationForm == null)
{
XmlSerializer xs = new XmlSerializer(typeof(InitiationForm));
XmlTextReader xtr = new XmlTextReader(new StringReader(workflowProperties.InitiationData));
_initiationForm = (InitiationForm)xs.Deserialize(xtr);
}
return _initiationForm;
}
}

Wednesday, 3 June 2009

The following URL is not valid: Error when publishing an InfoPath 2007 form to a SharePoint Library

As per the following link http://joeshepherd.spaces.live.com/blog/cns!9AE2097A4A610B63!137.entry, there is an issue with the System Event Notification Service that will prevent publication of an InfoPath form when there is not network connection (e.g. your Virtual Machine has network connectivity disabled). To fix this issue, disable the System Event notification service while publishing your InfoPath form template.

As per my previous post (http://ddkonline.blogspot.com/2009/02/fix-error-occurred-either-in-outlook-or.html - related to an Outlook issue) you can do this by typing the following at a command prompt:
  1. At a command prompt, type "net stop sens" and Enter
  2. Publish your InfoPath form
  3. Then to restart it, type "net start sens".

InfoPath 2007 Forms using Forms Services in SharePoint 2007 - "This form cannot be opened. It is not workflow enabled."

You may find that when you try and open an InfoPath form (e.g. as the initiation form of a workflow) that it just says "This form cannot be opened. It is not workflow enabled".

If you go to Central Administration -> Applications Management -> Manage Form Templates, it will show your form with the Status of Installing on a permanent basis. This will never complete - so what can you do about it?

This is because the real error when uploading your form is hidden so the install of the form never completes. To discover the real error, click on the "Upload Form Template" button. Enter the file name of your Infopath template (xsn) file (typically located at http://myserverurl/_admin/UploadFormTemplate.aspx) and click the "Verify" button. Resolve these issues and the InfoPath form will deploy and install properly.

The issue I had was that:
  1. I had created a new InfoPath form
  2. I had published it but had not left the section entitled "If users access the form template from the published location by using a different path, such as a public URL or full network path, enter it below, and then click Next." section BLANK (otherwise it won't work)
  3. You need to use the published version of the Form template, not the original design.