Hi,
I have a CSLA 4 project that encountered an issue as soon as I upgraded it to beta 3 or RC0. In my project I have a ReadOnlyBase object. In my DataPortal_Fetch method, I am calling LoadProperty(PropertyInfo, object) - the non-generic version. This call throws a NotSupportedException on line 288 of MethodCaller.cs. The Exception message says "The property 'MyProperty' on Type 'Business.MyBusinessObject' does not have a public setter." This is of course true because this is a read-only object.
If I change my LoadProperty call to use the generic method instead, then I do not receive the exception. In fact, if I use that generic method instead, the CallPropertySetter(object,string,object) method in MethodCaller.cs (where the exception occurs) never even gets called.
I see in the change log that LoadProperty was modified to bring parity between the generic and non-generic method, but perhaps this is not the case?
Any help would be very much appreciated!
Just ran into a similar problem with one of my classes after upgrading to the RC. I was trying to load an int into a short property without casting first. After adding an explicit cast in the method call, the error went away.
This is because of a change in the RC release where the non-generic LoadProperty() now invokes the property setter, thus (indirectly) invoking the generic LoadProperty() to get the same behavior.
This change means you now need to have a setter (public in SL, non-public is fine in .NET) on your property. That setter should call LoadProperty().
I typically do this regardless - even my read-only properties have a private setter that calls LoadProperty().
This is because of a change in the RC release where the non-generic LoadProperty() now invokes the property setter, thus (indirectly) invoking the generic LoadProperty() to get the same behavior.
This change means you now need to have a setter (public in SL, non-public is fine in .NET) on your property. That setter should call LoadProperty().
I typically do this regardless - even my read-only properties have a private setter that calls LoadProperty().
I am not happy with the change we made to the non-generic LoadProperty() - this change that requires properties to have a setter.
So I just checked in a change so the non-generic LoadProperty() now uses reflection to invoke the generic LoadProperty(). This means that no setter is required, and the non-generic implementation has the same behavior as the generic implementation (since it just invokes the generic implementation).
The only drawback to this approach is that reflection is involved, so there's a potential performance impact. But this may be the best overall solution, since it ensures the same behavior, doesn't force me to duplicate a bunch of complex code and doesn't force properties to have setters.
Where's the link from which to download the latest RC that incorporates this change (I guess it's RC1 4.0.0-100719)? The read-only LoadProperty thing is important.
Cheers!
Yes, the change should be in RC1 - http://www.lhotka.net/cslanet/download.aspx
Hmmm - that's the release I'm using now. The bug still appears in Command objects inheriting from CommandBase that contain read-only objects.
I mean - read only properties.
Arg! Yeah, my bad. Probably doesn't work in ROB either
OK, I fixed that issue (with a couple new unit testing bits). The fix is in svn, so if you pull the latest code you can have the fix now, otherwise it will be in RTM.
Copyright (c) Marimer LLC