Property Copy Failed

Property Copy Failed

Old forum URL: forums.lhotka.net/forums/t/817.aspx


fargs posted on Friday, August 04, 2006

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)
   Dim rules As ValidationRulesManager = RulesToCheck
   If rules IsNot Nothing Then
   //It's failing because the rules.GetRulesForProperty method is returning nothing and it is trying to call GetList    
   //There are no rules for this property
   Dim list As List(Of IRuleMethod) = rules.GetRulesForProperty(propertyName, False).GetList(True)
      If list IsNot Nothing Then
         CheckRules(list)
      End If
   End If
End Sub

Les

fargs replied on Friday, August 04, 2006

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?

 

Brian Criswell replied on Friday, August 04, 2006

I believe you are running in to this problem:
http://forums.lhotka.net/forums/permalink/4040/4164/ShowThread.aspx#4164

fargs replied on Friday, August 04, 2006

That's great. Thanks.

Where can I get the fix that Rocky has checked in?

Brian Criswell replied on Friday, August 04, 2006

search the forums and Rocky's site for "CVS".

Moe replied on Thursday, June 14, 2007

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 Then

propertyInfo.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 value

propertyInfo.SetValue(target, value, Nothing)

Else

' types don't match, try to coerce types

If pType.Equals(GetType(Guid)) Then

propertyInfo.SetValue(target, New Guid(value.ToString), Nothing)

ElseIf pType.IsEnum AndAlso vType.Equals(GetType(String)) Then

propertyInfo.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) Then

value = "0"

propertyInfo.SetValue(target, _

Convert.ChangeType(value, pType), Nothing)

Else

propertyInfo.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) Then

value = "0"

propertyInfo.SetValue(target, _

Convert.ChangeType(value, pType), Nothing)

Else

propertyInfo.SetValue(target, _

Convert.ChangeType(value, pType), Nothing)

End If

'-------------------------------------End of Modification---------------------------------------------------------

Else

propertyInfo.SetValue(target, _

Convert.ChangeType(value, pType), Nothing)

End If

End If

End If

End Sub

I hope this helps

 

Moe

skaue replied on Thursday, December 06, 2007

Call me lazy, but does anyone have this in c#

The datamapper is driving me nutz atm :-/

skaue replied on Friday, December 07, 2007

c# variant located here:
http://forums.lhotka.net/forums/permalink/19598/19598/ShowThread.aspx#19598

:-)

Copyright (c) Marimer LLC