Need help with PropertyHasChanged() error

Need help with PropertyHasChanged() error

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


TooMuch posted on Friday, March 14, 2008

I have a databound textbox that throws a System.StackOverflowException in Csla.dll everytime I try to update the value of the databound textbox .  Here is the call stack when the exception is thrown:

Csla.dll!Csla.Core.BindableBase.OnPropertyChanged(string propertyName = "SiteID") Line 102 C#
Csla.dll!Csla.Core.BusinessBase.PropertyHasChanged(string propertyName = "SiteID") Line 276 C#
Csla.dll!Csla.Core.BusinessBase.PropertyHasChanged() Line 257 C#
ClaimAudit.Biz.dll!ClaimAudit.Biz.ClaimAudit.SiteID.set(string value = "249000029") Line 589 + 0x8 bytes C#
[External Code] 
ClaimAudit.Windows.exe!ClaimAudit.Windows.Program.Main() Line 21 + 0x1a bytes C#

and here is the SiteID property that is bound to the textbox:

public string SiteID

{

         [MethodImpl(MethodImplOptions.NoInlining)]

         get

         {

                  CanReadProperty(true);

                  return _siteID;

         }

         [MethodImpl(MethodImplOptions.NoInlining)]

         set

         {

                  CanWriteProperty(true);

                  if (_siteID != value)

                  {

                           _siteID = value;

                           PropertyHasChanged();

                  }

         }

}

This is the line in BindableBase.OnPropertyChanged that is throwing the exception:

_nonSerializableHandlers.Invoke(this, new PropertyChangedEventArgs(propertyName));

 

Can anyone give me some insight into what I am doing incorrectly?

 

RockfordLhotka replied on Saturday, March 15, 2008

You probably have some code in your UI that is triggered when the control's value changes, and then it changes the value of the property on the control or object - thus causing an endless loop.

TooMuch replied on Sunday, March 16, 2008

I get what you're saying about the endless loop, that would explain the StackOverflowException.  So after reading your message, I took the windows form and stripped it down to one textbox that is bound to the SiteID property of my business object via the designer (dragging from Data Sources) and the only code behind the form is the following:

using System;

using System.Windows.Forms;

namespace ClaimAudit.Windows

{

         public partial class ClaimAuditFormTest : Form

         {

                  public ClaimAuditFormTest(ClaimAudit.Biz.ClaimAudit claimAudit)

                  {

                  InitializeComponent();

                  ClaimAuditBindingSource.DataSource = claimAudit;

                  }

         }

}

Yet I still get the same System.StackOverflowException in Csla.dll exception when after editing the SiteId textbox.  Since there is now next to nothing in the code behind the form, where could this endless loop be occurring?

 

RockfordLhotka replied on Sunday, March 16, 2008

Use the debugger and trace through. Obviously you have some code (not in the UI apparently) that is triggered when your property changes, and is then changing the property.

 

Rocky

 

 

From: TooMuch [mailto:cslanet@lhotka.net]
Sent: Sunday, March 16, 2008 7:33 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Need help with PropertyHasChanged() error

 

I get what you're saying about the endless loop, that would explain the StackOverflowException.  So after reading your message, I took the windows form and stripped it down to one textbox that is bound to the SiteID property of my business object via the designer (dragging from Data Sources) and the only code behind the form is the following:

using System;

using System.Windows.Forms;

namespace ClaimAudit.Windows

{

         public partial class ClaimAuditFormTest : Form

         {

                  public ClaimAuditFormTest(ClaimAudit.Biz.ClaimAudit claimAudit)

                  {

                  InitializeComponent();

                  ClaimAuditBindingSource.DataSource = claimAudit;

                  }

         }

}

Yet I still get the same System.StackOverflowException in Csla.dll exception when after editing the SiteId textbox.  Since there is now next to nothing in the code behind the form, where could this endless loop be occurring?

 



TooMuch replied on Tuesday, March 18, 2008

Ok, this one was a hard one to track down because I couldn't use the normal methods of debugging/tracing since the error was occurring in the BindableBase.OnPropertyChanged event with the line:

_nonSerializableHandlers.Invoke(this, new PropertyChangedEventArgs(propertyName));

 

Since you can't step into that call while debugging it made it more difficult to catch.  But the StackOverflowException was being caused by my business objects override of GetIdValue, which in hindsight was terribly wrong, but it looked like this:

protected override object GetIdValue()

{

         return this;

}

That's a definite no-no since this will be called by Equals() and creates the endless loop, I changed the override to the following:

protected override object GetIdValue()

{

         return this._auditID;

}

Thanks for the assistance in helping me track down the exception, I'm still learning the intracacies of the Csla framework!

Copyright (c) Marimer LLC