Over a million developers have joined DZone.

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

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)

    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.

mobile ,windows phone ,c++

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}