Friday, September 14

Windows Workflow : Dependency Property "does not define a static dependency property with name"

If you encounter the below exception while registering a DependencyProperty

"Error 103 Could not create activity of type 'xxxxxxxxxxxxxx'. System.ArgumentException: Type 'xxxxxxxxxx' does not define a static dependency property with name 'xxxxxxProperty'.
Parameter name: ownerType
   at System.Workflow.ComponentModel.DependencyProperty.ValidateAndRegister(String name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, Type validatorType, Boolean isRegistered)
   at System.Workflow.ComponentModel.DependencyProperty.Register(String name, Type propertyType, Type ownerType)
   at xxxxx..cctor()"

Fix:

If you are registering Dependency Property with name 'XYZ' then the declaration should be exactly like this,

public static DependencyProperty XYZProperty = DependencyProperty.Register("XYZ", typeof(bool), typeof(ApprovalWorkflow));
        public bool IsRestarted
        {
            get { return ((bool)(GetValue(XYZProperty ))); }
            set { SetValue(XYZProperty , value); }
        }

Variable name  should end with 'Property' and start with one passed to 'Register' method
VariableFormat Example  (<XYZ><Property>).

Please share your comments if it helps.