Thursday 11 December 2014

Navigating away from a page in Windows Phone 8.1 with Prism throws a System.ArgumentNullException

I just had a little headache with something that should be fairly trivial, but unfortunately the exception & stack trace weren't particularly descriptive. I was navigating from one page to another in my universal app. The navigation worked for Windows, but not for Phone, and I got the following:

{System.ArgumentNullException: Value cannot be null.
Parameter name: key
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
   at Microsoft.Practices.Prism.StoreApps.VisualStateAwarePage.OnNavigatedFrom(NavigationEventArgs e)}


Well it turns out when you create a new Windows Phone XAML page in Visual Studio, it kindly overrides the OnNavigatedTo method in the code behind (of course I didn't look here, I'm using MVVM!), which seems to throw Prism out of whack. Remove the overriden method (or just call it's base) and navigation succeeds, yippee.

2 comments: