CSLA 4.0 Beta 2 BusinessBase Error Handling Problem?

CSLA 4.0 Beta 2 BusinessBase Error Handling Problem?

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

SWITCH posted on Monday, June 14, 2010

Hi there!

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");
  return CanReadProperty(prop);

RockfordLhotka replied on Monday, June 14, 2010

Thank you - that is clearly a mistake, and it was intended to be FirstOrDefault.

bniemyjski replied on Monday, June 14, 2010


This has been fixed in the latest nightly build.


-Blake Niemyjski

SWITCH replied on Friday, June 18, 2010

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