Welcome to MSDN Blogs Sign in | Join | Help

Displaying Validation Errors in a Rehosted WF4 Designer

Here’s a quick one

“I’d like to find out if the workflow in the designer is valid… is there someway to retrieve the validation errors?”

Yes, the short answer is that you need to provide an implementation IValidationErrorService.  There is one important method to implement on this interface, ShowValidationErrors which will pass you a list of ValidationErrorInfo objects.

The next thing that needs to happen is that you need to publish an instance of that new type to the editing context.

Let’s look at a really simple implementation that will write out the validation errors to the debug log.

using System.Activities.Presentation.Validation;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace VariableFinderShell
{
    class DebugValidationErrorService : IValidationErrorService
    {
        public void ShowValidationErrors(IList<ValidationErrorInfo> errors)
        {
            errors.ToList().ForEach(vei => Debug.WriteLine(string.Format("Error: {0} ", vei.Message)));
        }
    }
}

The final bit is to publish this to the editing context:

wd.Context.Services.Publish<IValidationErrorService>(new DebugValidationErrorService());

Now, when editing the workflow in the rehosted app, let’s introduce some errors and then look at the output window.  Note, most of the errors below come from incorrect expressions introduced in the expression editor (putting integers in the wrong place, wrong variable name, etc).

 

image

Published Friday, November 06, 2009 6:55 PM by mwinkle

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Displaying Validation Errors in a Rehosted WF4 Designer

Wonderful, good to know. I really need to add this stuff on my own re-hosted designer!

Monday, November 09, 2009 2:15 AM by Adriano

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker