Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Unexpected Windows Phone Errors

DZone's Guide to

Unexpected Windows Phone Errors

If you've experienced issues in Windows Phone 8 where your active tile won't display, this tutorial may help solve that problem.

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

I've been updating an app that targets WP8.0.

In my free time, I've been looking through the dev center health reports to see if there are any exceptions occurring that I can do anything about.

It seems that I've not been defensive enough in my coding and previously didn't allow for things that should never happen from happening.

Yes, really.

Even if it's not displayed, an app should always have one tile, the "primary tile," that can be accessed in code so it can be updated.

Like this:

var primaryTile = ShellTile.ActiveTiles.First();

Except when it can't.

According to the stack traces, the above has failed.

The lesson? Always use `FirstOrDefault()` even when there should always be at least one and you want the first.

A page has a State dictionary that can be used for storing details while the app is deactivated/tombstoned.

You should always be able to access it and it should always exist:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    if (this.State.Count > 0) 
    {

But then, apparently (according to the exception details) there may be an exception when accessing the `State` property.






For an app with over a million installs the number of times the above have happened is incredibly small, but may be worth noting if you want to be super robust in your code.

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:
mobile ,windows phone ,c++

Published at DZone with permission of Matt Lacey, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}