3

I've been struggling for a week with a bug in my published UWP app that only seems to manifest itself in release mode when deployed on phones (ARM target). It randombly crashes the app when navigating from one specific page to another. It only affects those two specific pages, even if their structure is identical to many others in the project that never show this behavior (usage of the OnNavigatedTo and OnLoaded to present the content and fill the ViewModel, etc)

The only clue I have (since I'm unable to get a full stacktrace) is this error message, which I am able to get with great difficulty by trial and error:

[Exception](http://i.imgur.com/9Mpejje.jpg)

It seems to be pretty generic and I've tried several things I found when looking for it:

  • Ensuring my IValueConverters never return null or unexpected values.
  • Ensuring no variables are left uninitialized.
  • Ensuring the UI is completely loaded before accessing any of its components.
  • Ensuring there are no UI manipulations outside of the Dispatcher thread.
  • Updating my project libraries (Newtonsoft JSON and winfbsdk, while the latter is not used in neither of the views).

After a lot of reading I tried to fiddle with the compilation options in the project settings, and found out that the offending configuration is having activated both the .NET native toolchain compilation AND the code optimization checkboxes. I managed to reproduce the crash in Debug mode with those options activated (basically playing with the app until randomly the bug would appear) but due to precisely those settings being activated, I got no stacktrace. The debugger simply breaks on the Unhandled XAML exception line and even the sender and e arguments of the method that launches it are "not accesible at the moment".

On the other hand, I got a few minidumps on my phone that I am unable to debug in Visual Studio 2015. It can't find the kenelbase.pdb symbols, even if I have the Microsoft Symbol Servers checked on my configuration.

I can't to upload the app to the store even if I left the .NET native compilation option checked (it seems to need both, the website throws an error during validation otherwise), so my users will eventually run into the bug. If anyone has any pointers or ideas, I would be really grateful.

Edit 0:

VS Enterprise 2015, W10M compilation 10586.107 running on a Lumia 925. I wish I'd knew why it doesn't update to .164, though.

Edit 1:

I have noticed that when the crash happens, none of several images I have on my view get loaded. There are some BitmapIcons loaded from bundled content (png) and two images loaded from network using an IValueConverter to turn them into BitmapImage and therefore, ImageSources. I have checked and rechecked the converter for nulls and exceptions, should be clear.

Edit 2:

Parent view, event that triggers navigation:

    private void SessionList_ItemClick(object sender, ItemClickEventArgs e)
    {
        Frame.Navigate(typeof(ClubPage), e.ClickedItem); // The collection is binded, so the clicked item is a model
    }

Code executed on the crashing view:

    private void ClubPage_Loaded(object sender, RoutedEventArgs e)
    {
        isInfoShowing = false;
        isLogoZoomed = false;
        compositor = ElementCompositionPreview.GetElementVisual(sender as UIElement).Compositor;
        Visual status = ElementCompositionPreview.GetElementVisual(StatusBlock);
        status.Opacity = 0.0f;
        ClubViewModel.Current.ShowIn = false;
        ClubViewModel.Current.ShowComing = false;
    }

    protected override async void OnNavigatedTo(NavigationEventArgs e)
    {
        if (e.Parameter != null)
        {
            ClubViewModel.Current.Club = e.Parameter as Club;
            SplitViewShellViewModel.Current.Title = ClubViewModel.Current.Club.Name.Replace("_", " ");
            SplitViewShellViewModel.Current.TitleBarOpacity = 1.0f;
            ClubViewModel.Current.InLimit = App.RefreshLimit;
            ClubViewModel.Current.ComingLimit = App.RefreshLimit;
            await ClubViewModel.Current.GetClub(); //I'm positive that up until this point the code is executed
            await ClubViewModel.Current.GetPeopleIn();
            await ClubViewModel.Current.GetClubNotifications();
        }
    }

Edit 3:

Activating Native debugging gives me the following stacktrace:

enter image description here

The Exception is raised when a DispatcherTimer ticks (I have none in my view, everything is internal). Besides that, I couldn't make any sense of it.

I have tried everything I could think of and I also refactored my whole view. The only "strange" thing I'm doing is a ListView inside a container that breaks its virtualization, but I'm not concerned about performance as the list is really small.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • 1
    https://blogs.msdn.microsoft.com/ntdebugging/2014/01/13/debugging-a-windows-8-1-store-app-crash-dump/ – Hans Passant Mar 26 '16 at 12:58
  • Do you serialize something when navigate to/from page? If yes -> you should add this namespace\classes\etc to [ProjectName].rd.xml file in Properties. – Mykyta Bondarenko Mar 26 '16 at 13:02
  • @NikitaBondareko not exactly there, but I do call an async method (awaited, returns a Task) from my viewmodel that might call another one that in turn does some http calls to a JSON REST API... what should I add then? The structure is: (crashing) View -> ViewModel -> Service which does the call and deserialization. – Gregorio Juliana Mar 26 '16 at 13:10
  • most likely a problem in the absence of metadata of you objects. How it do you can find here - https://msdn.microsoft.com/en-us/library/dn600638(v=vs.110).aspx – Mykyta Bondarenko Mar 26 '16 at 13:19
  • @NikitaBondarenko modified Properties/Default.rd.xml and it still crashes =/. – Gregorio Juliana Mar 26 '16 at 13:36
  • Following @HansPassant link and finally getting the right symbols (until hitting kernelbase.pbd), leads me to this less than ideal [stacktrace](http://i.imgur.com/rntphid.jpg) – Gregorio Juliana Mar 26 '16 at 14:10
  • @GregorioJuliana, try comment request and parsing -> will working normally or will crash too? – Mykyta Bondarenko Mar 26 '16 at 14:50
  • the e.ClickedItem is going to be serialized in the navigation history file - you'll need to add the type of that in the rd.xml file. (I mean the actual type of the clickeditem.) – Tamás Deme Mar 26 '16 at 14:57
  • @NikitaBondarenko still crashing. Took a while longer, though, but same exception. – Gregorio Juliana Mar 26 '16 at 15:00
  • @TamásDeme I have added the whole namespace of the models (there are actually two), to no avail =/ – Gregorio Juliana Mar 26 '16 at 15:01
  • @GregorioJuliana, now try comment you xaml step by step while app will not crash – Mykyta Bondarenko Mar 26 '16 at 15:29

1 Answers1

3

This is incredibly odd (for me at least), but apparently the navigation code shown above wasn't executing on the Dispatcher thread...even if it was triggered by an UI event. Sending the call to the dispatcher as follows did the trick:

private async void SessionList_ItemClick(object sender, ItemClickEventArgs e)
{
   await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Frame.Navigate(typeof(ClubPage), e.ClickedItem)); 
}

Identical code (without the explicit Dispatcher.RunAsync wrapper) spread across the whole app works as expected. Every time I've run into UI thread issues the exceptions thrown were managed and easy to reproduce...what could possibly be happening during the compiler optimization process that could trigger this?

  • Hello! I work on the .NET Native runtime and compiler team. Sorry to hear it's giving you trouble. It sounds like you can get the problem to manifest itself in DEBUG with .NET Native enabled which should help track this down. One suggestion that I have is to stop on all first chance exceptions (Debug > Window > Exception settings > check Common Language Runtime box). Lots of components catch exceptions that that they have no business dealing with so that's often pretty helpful. Feel free to email us as dotnetnative@microsoft.com... some other folks may have some more ideas. – MattWhilden Mar 28 '16 at 19:22
  • @MattWhilden Hi! Thanks for stopping by, really appreciate it. I did as you said (actually I checked them all, just in case) and all I got after finally reproducing the bug was this: [Exception](http://i.imgur.com/B85hZhb.jpg). As stated before, I only find this problem with the "Optimize code" option checked besides the .NET native compilation one, so I guess that's why I am not getting more information. – Gregorio Juliana Mar 28 '16 at 21:24
  • Thanks Matt this has helped me, I was getting an error ExcectionHelpers.cs not found, turns out to be a problem in a weather PCL. – 27k1 Apr 23 '16 at 07:59
  • I also have an app that works fine in Debug mode but has all sorts of Dispatcher errors in release mode. I suspect that it has something to do with the fact that I am calling the dispatchers via an extension method. – William Jockusch Jan 17 '17 at 17:51
  • Thanks! This helped a lot – Billy Jake O'Connor Jan 25 '17 at 23:06