[Solved] StackOverFlow-Exception after changing value of Property


This is a simple logical error and a problem of “infinite recursion” because the CurrentState property is attempting to set itself. The solution is simple.

Currently you have this (simplified)

public State CurrentState {
    set {
        // ...

        CurrentState = state.Whatever;

        // ...
    }
    get {
        return ???; /// ??? => I don't know what you're returning?
    }
}

Solution: Create a backing field so the property doesn’t call itself.

private State _currentState;

public State CurrentState {
    set {
        // ...

        // This is for illustration purposes. Normally you'd be checking 
        // or assigning the value of the "value" parameter, not always 
        // setting the same value as this suggests.
        _currentState = state.Whatever;

        // ...
    }
    get {
        return _currentState;
    }
}

solved StackOverFlow-Exception after changing value of Property