Validation Fails on Build  
Author Message
David Mann [MVP]





PostPosted: Windows Workflow Foundation, Validation Fails on Build Top

Hi,

I've written a custom validator for my Activity which works fine in the IDE - I get the expected error indicators. However, my project still compiles OK - i.e. I don't get a build error saying that my custom Property is not set. Code is below. I need to ensure that the workflow builder supplies a value for this property before deploying the workflow. Any ideas

Thanks.

______________________

public override ValidationErrorCollection Validate(ValidationManager manager, object obj)

{

ValidationErrorCollection vecmyProperty = base.Validate(manager, obj);

myActivity ma = obj as myActivity;

if (String.IsNullOrEmpty(ma.myProperty))

{

ValidationError verrmyProperty = ValidationError.GetNotSetValidationError("myProperty ");

vecmyProperty .Add(verrmyProperty );

}

return vecmyProperty ;

}



Software Development for Windows Vista9  
 
 
Arjun Banker





PostPosted: Windows Workflow Foundation, Validation Fails on Build Top

Dave,

Since you said this works in the IDE for you, I'm guessing the validation is not working in some scripted build environment you have set up You should make sure you invoke wfc.exe, instead of csc.exe, to ensure that the validators are run.

HTH,

Arjun


 
 
DaveM.





PostPosted: Windows Workflow Foundation, Validation Fails on Build Top

Arjun,

Thanks for the reply. I didn't explain things too well. What's happening in the IDE is that I get the indicators that my Property does not have a value - the little exclamation point in the red circle in the Designer and the Property window. So that part works OK and I know my custom Validator is loading and functioning. However, when I build the project, the build succeeds, even if I don't supply a value for that Property. With other out of the box Activities, the project won't compile if a required Property is missing a value. The compiler reports an error. I need mine to act the same way. This is all happening right in the IDE.

Is that clearer

Thanks again,

Dave


 
 
kushals





PostPosted: Windows Workflow Foundation, Validation Fails on Build Top

The following code should get the issue resolved -

using System;

using System.ComponentModel;

using System.ComponentModel.Design;

using System.Collections;

using System.Drawing;

using System.Workflow.ComponentModel;

using System.Workflow.ComponentModel.Design;

using System.Workflow.ComponentModel.Compiler;

using System.Workflow.ComponentModel.Serialization;

using System.Workflow.Runtime;

using System.Workflow.Activities;

using System.Workflow.Activities.Rules;

namespace WorkflowLibrary1

{

[ActivityValidator(typeof(ValidationClass))]

public partial class Activity1: SequenceActivity

{

public Activity1()

{

InitializeComponent();

}

public static DependencyProperty MyPropertyProperty = System.Workflow.ComponentModel.DependencyProperty.Register("MyProperty", typeof(string), typeof(Activity1));

[Description("This is the description which appears in the Property Browser")]

[Category("This is the category which will be displayed in the Property Browser")]

[Browsable(true)]

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]

public string MyProperty

{

get

{

return ((string)(base.GetValue(Activity1.MyPropertyProperty)));

}

set

{

base.SetValue(Activity1.MyPropertyProperty, value);

}

}

}

class ValidationClass : Validator

{

//override

public override ValidationErrorCollection Validate(ValidationManager manager, object obj)

{

ValidationErrorCollection vecmyProperty = base.Validate(manager, obj);

Activity1 ma = obj as Activity1;

if((ma.Parent != null) || (ma.Activities.Count != 0))

{

if ((String.IsNullOrEmpty(ma.MyProperty)) )

{

ValidationError verrmyProperty = new ValidationError("Validation Failed", 1, false, "MyProperty");

vecmyProperty.Add(verrmyProperty);

}

}

return vecmyProperty;

}

}

}

Thanks,

Kushal.