Adding a tile to Windows Phone (Annoying and unhelpful errors - Part 2)

February 17, 2015

Following on from this post, I encountered the following error:

Value does not fall within the expected range.

Here’s the culpable code again:



SecondaryTile tileData = new SecondaryTile()
{
    TileId = title,
    DisplayName = title,
    Arguments = arguments
};
tileData.VisualElements.Square150x150Logo = new Uri("ms-appx:///assets/TileIcon150x150.png");
tileData.VisualElements.ShowNameOnSquare150x150Logo = true;

And, as is typical with these things, it worked yesterday, when I wrote the above post. So, why now, when I run it, does it point to the instantiation of `SecondaryTile` above and cry foul?

This time, it was caused by the ID containing an invalid character (a space). Something similar to the following will fix it:



SecondaryTile tileData = new SecondaryTile()
{
    TileId = title.Replace(" ", ""),
    DisplayName = title,
    Arguments = arguments
};
tileData.VisualElements.Square150x150Logo = new Uri("ms-appx:///assets/TileIcon150x150.png");
tileData.VisualElements.ShowNameOnSquare150x150Logo = true;



Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2024