3.5 Beta Release Bug Report - Fails when adding new BusinessBase items to a collection

3.5 Beta Release Bug Report - Fails when adding new BusinessBase items to a collection

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


bitburner posted on Thursday, January 31, 2008

I found a bug today in the PropertyInfo feature when attempting to add a BusinessBase Derived instance to a BusinessListBase derived instance.

It happens with Nullable Types - I am using a nullable integer for one of my fields (Registered as a propertyInfo) - the FieldManager attempts to find the field and compares values - the chokes when it encounters the nullable value.

Here is a stack trace (omiting the UI stuff since it's not the cause)...

   at Csla.Core.FieldManager.FieldDataManager.FindProperty(Object value) in C:\CSLA SVN\cslacs\Csla\Core\FieldManager\FieldDataManager.cs:line 132
   at Csla.Core.BusinessBase.Child_ListChanged(Object sender, ListChangedEventArgs e) in C:\CSLA SVN\cslacs\Csla\Core\BusinessBase.cs:line 2276
   at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.InsertItem(Int32 index, T item)
   at Csla.BusinessListBase`2.InsertItem(Int32 index, C item) in C:\CSLA SVN\cslacs\Csla\BusinessListBase.cs:line 451
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at MicroEdge.Phoenix.Business.FundRepresentativeCollection.AddNewCore() in C:\PhoenixWF\MicroEdge.Phoenix.Business\FundRepresentativeCollection.cs:line 109
   at System.ComponentModel.BindingList`1.System.ComponentModel.IBindingList.AddNew()
   at System.ComponentModel.BindingList`1.AddNew()
  

Here is where it happens in CSLA (FieldDataManager class)....

 internal IPropertyInfo FindProperty(object value)
    {
      var index = 0;
      foreach (var item in _fieldData)
      {
        if (item != null && item.Value.Equals(value))
        {
          return _propertyList[index];
        }
        index += 1;
      }
      return null;
    }

if item is a Nullable type set to null (in this case an "int?") - then the call to Equals will fail.  What's wierd about this bug is it worked fine until I changed my factory method to use DataPortal.Create<T> instead of just using the constructor.  But looking at this - I can't see how it ever worked - does using dataportal.create<T> instead of just creating the object directly change when this particular method is called?

 

Chase

 

RockfordLhotka replied on Thursday, January 31, 2008

I'm puzzled. FindProperty() is only called in relation to child objects, not to regular values.

Oh I see, it is handling the child's listchanged event, and runs into your null field because the IFieldData object is non-null, but item.Value is null.

Yup, that's a bug - thanks!! I think it should read:

internal IPropertyInfo FindProperty(object value)
{
 
var index = 0;
 
foreach (var item in _fieldData)
  {
   
if (item != null && item.Value != null && item.Value.Equals(value))
     
return _propertyList[index];
    index += 1;
  }
 
return null;
}

Copyright (c) Marimer LLC