Tuesday, March 6, 2012

public get, private set, public crash?


Goodness,  I seem to have found the weirdest bug. I decided to pull all the event headings into the Schedule class ("Manticore" etc) as a precursor to loading these dynamically from a settings file.  I set up the lists like this:

        
public List<string> eventDays
        {
            
get { return eventDays; }
            
private set { }
        }

However, all of a sudden I found that the app would completely and silently crash, not even throwing an exception for me, when it tried to access any of these list variables - even from within the same class. I removed the get/set so they were just public variables, and the app worked fine again. Then I put back this get/set code, and the app crash reliably reproduced, and then visual studio itself crashed.

    public Schedule()
        {
            
ObservableCollection<Event> events = new ObservableCollection<Event>();
            Events = events;
            eventDays = 
new List<string>();
        }

        private void readSchemaFile()
        {
            
if (eventLocations == null)
            {
                eventLocations = 
new List<String>();
            }
   //populate list
      }


edit: the next day, when it was not 2am, someone pointed out to me that I had obviously put a recursive get on eventDays, so it was crashing with a stack overflow. Way to go, me. 

No comments: