Strange stack trace on Windows phone 8

0

I have my app in Windows Phone store and from the reports I can see couple of crashes with following stack trace:

Problem function
MyApp.InputPage+_populateLocationList_d__0.MoveNext

Exception type
system.nullreferenceexception

Stack trace
"Frame    Image          Function                                                                   Offset        
0        myapp_ni       MyApp.InputPage+_populateLocationList_d__0.MoveNext    0x00000050    
1        mscorlib_ni    System.Runtime.CompilerServices.AsyncMethodBuilderCore._ThrowAsync_b__0    0x00000036"

Yes, i know the issue is in InputPage populateLocationList method, but the method is quite complex. Any idea what could cause this? How to debug this since im unable to reproduce the error my self.

And this is my populateLocationList:

private async void populateLocationList(object sender, EventArgs e)
{
    String searchString = this.locationTextBox.Text;

    var geoCodesList = new List<GeocodeResponse>();

    if (searchString.Length >= 3)
    {
        WebApiWorker webApi = new WebApiWorker();
        geoCodesList = await webApi.GetGeocodeAsync(searchString);
    }

    if (geoCodesList == null || geoCodesList.Count < 1)
    {
        noLocationsFoundText.Visibility = Visibility.Visible;
    }

    else
    {
        noLocationsFoundText.Visibility = Visibility.Collapsed;
    }

    this.routeLocationsList.ItemsSource = geoCodesList;
}
c#
windows-phone-8
stack-trace
asked on Stack Overflow Nov 18, 2013 by devha • edited Nov 19, 2013 by devha

1 Answer

0

Barring a bug in the async-await machinery (which is a vanishingly-small-but-nonzero possibility), there are four places in your method that could conceivably result in a NullReferenceException:

  • locationTextBox.Text
  • searchString.Length
  • noLocationsFoundText.Visibility
  • routeLocationsList.ItemsSource

Are you certain that none of these are null? Depending on how the async framework is handling error reporting, I also wouldn't rule out something blowing up in await GetGeocodeAsync, though the stack trace suggests otherwise.

Incidentally, why are you initializing a List<GeocodeResponse> and immediately overwriting it? It's not the problem here, but looks redundant.

To help you debug, as @devha suggests you can set your debugger to break as soon as a particular exception is thrown. In the 'Debug' menu, select 'Exceptions', and under CLR Exceptions check NullReferenceException. Now, whenever one of those is thrown while you are debugging, Visual Studio will immediately pause and show you the offending line.

answered on Stack Overflow Nov 19, 2013 by Ben

User contributions licensed under CC BY-SA 3.0