This project is read-only.
1
Vote

Stack Overflow with recursion circles

description

Hello,
 
I am trying out your framework, looks very good so far. I found a bug which occurs in the following Situation:
 
I have to 2 classes Referencing each other:
 
public class User {
public Usergroup{get;set;}
string Name {get;set;}
}
 
public class Usergroup {
public IList<User> Users {get;set;}
string Name {get;set;}
}
 
Now when doing the following I get a Stackoverflow due to the PropertyChanged Notification for IsValid bubbling back and forth.
 
var ug = new Usergroup{Name="group1";}
var u = new User {Name="user1";Usergroup = ug};
 
u,Usergroup = new Usergroup(){Name="group2"}
 
 
I did the following to solve the problem, but it's probably not the best solution.
 
In EntityExtensions.cs I changed RaisePropertyChanged(string proertyName, bool notifyParent) like this:
 
    private List<IEntityExtensions> visitedParents;
    public void RaisePropertyChange(string propertyName, bool notifyParent)
    {
        if (notifyParent)
            visitedParents= new List<IEntityExtensions>();
        RaisePropertyChangedInternal(propertyName,notifyParent);
    }
    private void RaisePropertyChangedInternal (string propertyName, bool notifyParent){
        var h = PropertyChanged;
        if (h != null)
            h(this, new PropertyChangedEventArgs(propertyName));
 
        if (notifyParent && Parent != null)
        {
            if (!visitedParents.Contains(Parent))
            {
                visitedParents.Add(Parent);
                ((EntityExtensions)Parent).RaisePropertyChangedInternal(propertyName, true);
            }
            else
            {
                visitedParents = null;
            }

        }
    }
 
One more thing: In the constructor of EntityBaseTemplate
 
    protected virtual IEntityExtensions CreateExtensions()
    {
        var entityExtensions = EntityExtensions.RegisterObject(this);
        entityExtensions.StartGraphMonitoring();
        return entityExtensions;
    }
 
  there is a call to StartGraphMonitoring, the method doesn't seem to exist anywhere ?
 
I replaced it with     entityExtensions.StartDirtyTracking();, is that correct ?

comments