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

February 14, 2015

Following this question on Stack Overflow, I tried using the following code to add a tile in Windows phone:



        public async Task<bool> CreateTile(string title)
        {
            SecondaryTile tileData = new SecondaryTile()
            {
                TileId = "MyTileID",
                DisplayName = "MyTilesTitle",
                Arguments = "Some arguments"
            };
            tileData.VisualElements.Square150x150Logo = new Uri("msappx:///assets/TileIcon150x150.png");
            tileData.VisualElements.ShowNameOnSquare150x150Logo = true;
            bool returnVal = await tileData.RequestCreateAsync();

            return returnVal;
        }

This gives the following mystifying error:

A first chance exception of type ‘System.ArgumentException’ occurred in Tile.Plugin.WindowsPhoneStore.DLL

Additional information: Value does not fall within the expected range.

Suspecting it related to the icons, I tried commenting the suspected offending code:



        public async Task<bool> CreateTile(string title)
        {
            SecondaryTile tileData = new SecondaryTile()
            {
                TileId = "MyTileID",
                DisplayName = "MyTilesTitle",
                Arguments = "Some arguments"
            };
            //tileData.VisualElements.Square150x150Logo = new Uri("msappx:///assets/TileIcon150x150.png");
            //tileData.VisualElements.ShowNameOnSquare150x150Logo = true;
            bool returnVal = await tileData.RequestCreateAsync();

            return returnVal;
        }

The error messages don’t get any more useful:

The parameter is incorrect.

Turns out that the problem was with the URI Scheme. The following worked fine:



        public async Task<bool> CreateTile(string title)
        {
            SecondaryTile tileData = new SecondaryTile()
            {
                TileId = "MyTileID",
                DisplayName = "MyTilesTitle",
                Arguments = "Some arguments"
            };
            tileData.VisualElements.Square150x150Logo = new Uri("ms-appx:///assets/TileIcon150x150.png");
            tileData.VisualElements.ShowNameOnSquare150x150Logo = true;
            bool returnVal = await tileData.RequestCreateAsync();

            return returnVal;
        }

Conclusion

So, the moral of the story is, don’t forget to hyphenate the msappx for Windows Phone, or you’ll get a misleading error.



Profile picture

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

© Paul Michaels 2024