Hi,
Can someone explain what would be causing this error. My object is bound to a grid. When i update and integer value (it is fine for strings) it causes a 'object not set to a reference' when the validation rules are checked for the property set.
Any ideas?
Public Sub CheckRules(ByVal propertyName As String)Les
I have narrowed down the error. I think this might be a bug. I am using CSLA 2.1.
When I add a validation rule to the property, everything works fine. But if I have a property without a validation rule in the grid, it will fail.
I believe if the GetRulesForProperty(propertyName, False) is changed to GetRulesForProperty(propertyName, True), it might resolve the issue, but i'm not sure if that will break anything else.
Will it?
That's great. Thanks.
Where can I get the fix that Rocky has checked in?
There are two things to check:
1. check that the property name matchs case in the object and in your binding expression "bind ("PropertyName")"
2. if you are using Datamapper class to populate your object, this class will cause this error if a text box is bound to an integer or decimal property. I had to modify The "SetPropertyValue()" method of this class to make it work for me
I marked the part I modified below
Public
Sub SetPropertyValue( _ ByVal target As Object, ByVal propertyName As String, _ ByVal value As Object) Dim propertyInfo As PropertyInfo = _target.GetType.GetProperty(propertyName)
If value Is Nothing ThenpropertyInfo.SetValue(target, value,
Nothing) Else Dim pType As Type = Utilities.GetPropertyType(propertyInfo.PropertyType) Dim vType As Type = Utilities.GetPropertyType(value.GetType) If pType.Equals(vType) Then ' types match, just copy valuepropertyInfo.SetValue(target, value,
Nothing) Else ' types don't match, try to coerce types If pType.Equals(GetType(Guid)) ThenpropertyInfo.SetValue(target,
New Guid(value.ToString), Nothing) ElseIf pType.IsEnum AndAlso vType.Equals(GetType(String)) ThenpropertyInfo.SetValue( _
target, System.Enum.Parse(pType, value.ToString),
Nothing) ' '------Modified Part Start Here ----- ElseIf pType.FullName = "System.Int32" And vType.FullName = "System.String" Then If value.Equals(String.Empty) Thenvalue =
"0"propertyInfo.SetValue(target, _
Convert.ChangeType(value, pType),
Nothing) ElsepropertyInfo.SetValue(target, _
Convert.ChangeType(value, pType),
Nothing) End If ElseIf pType.FullName = "System.Decimal" And vType.FullName = "System.String" Then If value.Equals(String.Empty) Thenvalue =
"0"propertyInfo.SetValue(target, _
Convert.ChangeType(value, pType),
Nothing) ElsepropertyInfo.SetValue(target, _
Convert.ChangeType(value, pType),
Nothing) End If '-------------------------------------End of Modification--------------------------------------------------------- ElsepropertyInfo.SetValue(target, _
Convert.ChangeType(value, pType),
Nothing) End If End If End If End SubI hope this helps
Moe
Copyright (c) Marimer LLC