Hi all,
I've implemented the Enterprise Library Validation Application Block (VAB) in our code to use validators in the Actipro WPF property grid. We create a validator attribute on our properties which controls the validation when we edit the property in the property grid. This all appears to be working fine with the validators correctly validating the value and showing error messages etc.
However, whenever I add a validator attribute to a property of an object edited through the property grid I get an inner exception thrown on any property (not just the one with the attribute) when edited. When I don't have a validator attribute present the property grid acts normally.
The inner exception is being thrown by the data property accessor when it attempts to set a value:
ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyGridDataAccessorItem.set_Value
We actually use a custom data property accessor but that simply wraps the set value method on the actipro class and does nothing special.
The exception is:
"A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=Value; DataItem='PropertyGridDataAccessorItem' (Name=''); target element is 'TextBox' (Name='textBox'); target property is 'Text' (type 'String') TargetInvocationException:'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Object must be of type Int32."
So it's expecting an Int32 object irrespective of what the actual property underlying type is. This only happens when I have a VAB attribute present on any property in the object being edited.
I've traced the code through and the call path is
PropertyGridDataAccessorItem.Value -> CustomDataPropertyAccessor.Value -> CustomPropertyDescriptor.SetValue(component, value)
Our custom classes don't actually change anything here and simply wrap the base behaviour. I've checked the component and value objects when we use the VAB attributes and when we don't and they appear to be identical. IDataErrorInfo is null, validation results count is zero and the component is flagged as being valid so it looks like the VAB is working correctly in both cases.
I'm now a little stumped as to what the issue is so was wondering whether you have any pointers?
I'm using the latest demo version of the WPF studio with the editors and the property grid editor interop. Note that I get the problem even when editing a string in a TextBox editor so nothing complex involved.
Cheers
Rick Edwards
I've implemented the Enterprise Library Validation Application Block (VAB) in our code to use validators in the Actipro WPF property grid. We create a validator attribute on our properties which controls the validation when we edit the property in the property grid. This all appears to be working fine with the validators correctly validating the value and showing error messages etc.
However, whenever I add a validator attribute to a property of an object edited through the property grid I get an inner exception thrown on any property (not just the one with the attribute) when edited. When I don't have a validator attribute present the property grid acts normally.
The inner exception is being thrown by the data property accessor when it attempts to set a value:
ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyGridDataAccessorItem.set_Value
We actually use a custom data property accessor but that simply wraps the set value method on the actipro class and does nothing special.
The exception is:
"A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=Value; DataItem='PropertyGridDataAccessorItem' (Name=''); target element is 'TextBox' (Name='textBox'); target property is 'Text' (type 'String') TargetInvocationException:'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Object must be of type Int32."
So it's expecting an Int32 object irrespective of what the actual property underlying type is. This only happens when I have a VAB attribute present on any property in the object being edited.
I've traced the code through and the call path is
PropertyGridDataAccessorItem.Value -> CustomDataPropertyAccessor.Value -> CustomPropertyDescriptor.SetValue(component, value)
Our custom classes don't actually change anything here and simply wrap the base behaviour. I've checked the component and value objects when we use the VAB attributes and when we don't and they appear to be identical. IDataErrorInfo is null, validation results count is zero and the component is flagged as being valid so it looks like the VAB is working correctly in both cases.
I'm now a little stumped as to what the issue is so was wondering whether you have any pointers?
I'm using the latest demo version of the WPF studio with the editors and the property grid editor interop. Note that I get the problem even when editing a string in a TextBox editor so nothing complex involved.
Cheers
Rick Edwards