I recently came across a problem (which I admit that I caused by accidentally binding the PropertyStatus control to an unregistered property on my Business Object) which has exposed some questionable error handling logic in the changes introduced in the BusinessBase.cs class in the new CSLA 4.0 Beta 2 Framework (in Silverlight).
In the CanReadProperty(...) methods (and CanWriteProperty(...) methods) in the BusinessBase class, if the propertyName is not found in the collection of registered properties, calling First() will throw an exception and the next line of code (the null reference check) will never be evaluated. The calling method HandleTarget() in the PropertyStatus.cs class also doesn't catch this exception which makes it a bit tricky to diagnose so I thought I would point it out. I haven't dug into this very deep but perhaps calling FirstOrDefault() would be a better way to attempt to retrieve the PropertyInfo object from the FieldManager?
public bool CanReadProperty(string propertyName)
var prop = FieldManager.GetRegisteredProperties().Where(c => c.Name == propertyName).First(); // Throws an exception!
if (prop == null)
throw new ArgumentOutOfRangeException("propertyName");
Thank you - that is clearly a mistake, and it was intended to be FirstOrDefault.
This has been fixed in the latest nightly build.
Glad I could help! Keep up the great work! I'm just getting into CSLA 4.0 but I'm loving the new changes!
Copyright (c) Marimer LLC