ParentBusinessObjectChanged event mishandled during Disposing


Author
Message
Kirk M Sherhart
Kirk M Sherhart
StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)
Group: Forum Members
Posts: 41, Visits: 259
I believe that I've found a bug in the BusinessLayer code involving the ParentBusinessObjectChanged event.  A reference to a null pointer is causing the application to throw an exception.

I have a ParentBO and ChildBO, with the proper ParentRelationship set up.  The ChildBO "attaches" to the ParentBO's FieldPropertyChanged event in order to listen for changes to field values.

The ChildBO has a handler for its ParentBusinessObjectChanged event as follows:

        private void ChildBO_ParentBusinessObjectChanged(ParentBusinessObjectChangedEventArgs e)
        {
            ParentBO parentBO;

            parentBO = e.PreviousParentBusinessObject as ParentBO;
            if (parentBO != null) {
                // Detach from old Parent BO
                parentBO.FieldPropertyChanged -= _parentBO_FieldPropertyChanged;
            }

            parentBO = e.NewParentBusinessObject as ParentBO;
            if (parentBO != null) {
                // Attach to the new Parent BO
                parentBO.FieldPropertyChanged += _parentBO_FieldPropertyChanged;
            }
        }


The problem occurs when the ParentBO is disposed.  The best I can tell, the sequence of events leading to the null reference exception is a follows:

  1. The application's form is closed, which causes...
  2. The ParentBO to be disposed, which eventually causes...
  3. The BusinessLayer.Dispose procedure to be called, which calls...
  4. The BusinessLayer.ForciblyRemoveAllHandlers() routine, which...
  5. Sets the value BusinessLayer._Handlers_MiscEvents to null, then...
  6. The BusinessLayer.Dispose procedure eventually calls the CleanUp() routine, which...
  7. Sets the ChildBO's ParentBusinessObject to null, which...
  8. Fires the ChildBO's ParentBusinessObjectChanged event with the e.PreviousParentBusinessObject==ParentBO, which...
  9. Tries to detach from the ParentBO's FieldPropertyChanged event, which...
  10. Causes a null reference exception in BusinessLayer.RemoveEventHandler route, because...
  11. The ParentBO's BusinessLayer._Handler_MiscEvents was set to null in step #5
Hope this helps toward an eventual fix.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search