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

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;

Leave a Reply

Your email address will not be published. Required fields are marked *