locked
Bug when using multiples Constraint on the same WorkflowElement within a TransactionScope RRS feed

  • Question

  • When I use multiples Constraint to validate a WorkflowElement, I get some strange errors in the ValidationResults when I'm in a TransactionScope. I use multiples constraints since I have some constraints types used by multiples WorkflowElement.

    Here is a sample to reproduce the bug:

    using System;
    using System.Activities;
    using System.Activities.Validation;
    using System.Collections.Generic;
    using System.Transactions;
    namespace TestElements
    {
       public static class TestClass
       {
          public static void Test ()
          {
             WorkflowElement realWorkflowDefinition = new TestElements.DoNothingWorkflowElement ();
             using (TransactionScope scope = new TransactionScope ())
             {
                // Uncomment the next line to solve the problem... else ValidationResults will have strange errors...
                // using (TransactionScope scopeSupress = new TransactionScope (TransactionScopeOption.Suppress))
                {
                   ValidationResults results = ActivityValidationServices.Validate (realWorkflowDefinition);
                   if (results.GetErrors ().Count > 0)
                      throw new InvalidOperationException ("#a Le workflow n'est pas valide.");
                }
             }
          }
       }
       public sealed partial class DoNothingWorkflowElement : NativeActivity
       {
          protected override void Execute (ActivityExecutionContext executionContext)
          {
          }
          protected override void OnGetConstraints (IList<System.Activities.Validation.Constraint> constraints)
          {
             Variable<DoNothingWorkflowElement> argument1 = new Variable<DoNothingWorkflowElement> () { Name = "argument1" };
             System.Activities.Validation.Constraint<DoNothingWorkflowElement> constraint1 = new System.Activities.Validation.Constraint<DoNothingWorkflowElement> ()
             {
                Body = new ActivityAction<DoNothingWorkflowElement, ValidationContext> ()
                {
                   Argument1 = argument1,
                   Handler = new TestConstraint (argument1),
                },
             };
             Variable<DoNothingWorkflowElement> argument2 = new Variable<DoNothingWorkflowElement> () { Name = "argument2" };
             System.Activities.Validation.Constraint<DoNothingWorkflowElement> constraint2 = new System.Activities.Validation.Constraint<DoNothingWorkflowElement> ()
             {
                Body = new ActivityAction<DoNothingWorkflowElement, ValidationContext> ()
                {
                   Argument1 = argument2,
                   Handler = new TestConstraint (argument2),
                },
             };
             constraints.Add (constraint1);
             constraints.Add (constraint2);
          }
          private class TestConstraint : NativeActivity
          {
             public TestConstraint (InArgument<DoNothingWorkflowElement> activity)
             {
             }
             protected override void Execute (ActivityExecutionContext context)
             {
             }
          }
       }
    }
    

    Is is the expected behavior?
    Wednesday, October 7, 2009 2:12 PM

Answers

  • In beta 2, the OnGetConstraints doesn't exist anymore, so I won't need any fix for this bug.

    • Marked as answer by Instriker Tuesday, October 20, 2009 3:01 PM
    Tuesday, October 20, 2009 3:00 PM