Time Machine in action!
In the beginning of the video, we receive/stumble upon an exception while trying to refer to elements of data collection (Objects). As it quickly turned out, the collection was empty which happened to be the direct cause of the exception, and, at the same time, is a consequence of an error appearing somewhere in the code.At this point, we may stop the Microsoft Visual Studio debugger and use data collected by Time Machine for .NET.
We may access the data by clicking on the "Display received states" button which will load the recording. Loaded data will be presented as a preview of threads where events have been marked. Loaded data is presented in timeline form in the Thread View tool window. In some cases, like in our example, the Thread view will also show Time Machine markers. The red marker shows exactly where the unhandled exception appeared. Clicking on it shows the application state as it was when it crashed.
Let's get down to searching for the bug in code. First of all, it is necessary to check if the collection has been properly initialized. Within the Sector class in question, we move to the constructor where the Object collection instance has been created and the loop for adding objects to the collection can be found. Using the Find references function in the Time Machine, we see how often was the Add method used in the Object collection. Calling the function will automatically launch the window Marker View tool window where only the unhandled exception marker is visible. This clearly shows that the Add method has not been used in the Objects collection, so the code paths in Sector contstructor responsible for adding objects weren’t executed in runtime.
Once again we search the references in order to see how often was the Object collection initialized. This time, new markers are presented in the Marker View. By double clicking on the first marker we proceed to the initialization of the collection, then we move on to the following application states using state change controls. This way, we are able to learn what exactly went wrong while running the loop for adding objects to the collection.
Thus we are finally able to identify the troublemaker - the SectorSize property in the Owner object has 0 value which is invalid for this variable. By using state change controls we move to the method using the constructor in question and we preview available symbols. Amongst them we identify the sectorSize variable, which is one of the parameters for InitializeSectors function. By analyzing the history of how the variable has been used, we also discover that it has never been assigned to property SectorSize on the object SectorManager, which is the direct cause of the error. One simple assignment and the error is eliminated. Phew!
Back to list