2

I am trying to update a Windows 8 secondary tile directly using XML. However, I keep getting an exception that the identifier for the tile I pinned is invalid. I even tried pulling the identifier directly from Windows and then substituting that back into CreateTileUpdaterForSecondaryTile, but I'm still getting the same exception. Here's my code:

public async static void UpdateSecondarySectionTile()
{
    string tileXmlString = "<tile id='SecondaryTile-7-0'>"
                         + "<visual>"
                         + "<binding template='TileWideImage'>"
                         + "<image id='1' src='" + imageSource + "' alt='alt text'/>"
                         + "</binding>"
                         + "</visual>"
                         + "</tile>";

    // create a DOM
    Windows.Data.Xml.Dom.XmlDocument tileDOM = new Windows.Data.Xml.Dom.XmlDocument();
    tileDOM.LoadXml(tileXmlString);

    System.Collections.Generic.IReadOnlyList<Windows.UI.StartScreen.SecondaryTile> tileList = await Windows.UI.StartScreen.SecondaryTile.FindAllAsync();

    foreach (var tile in tileList)
    {
        string tileId = tile.TileId;
        Windows.UI.Notifications.TileNotification tileUpdate = new Windows.UI.Notifications.TileNotification(tileDOM);
        try
        {
            Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileId).Update(tileUpdate);
        }
        catch (Exception e)
        {
            System.Diagnostics.Debug.WriteLine("message: " + e.Message + ", inner exception: " + e.InnerException + " string: " + e.ToString());
        }
    }
}

The debug line is outputting:

//message: The application identifier provided is invalid.
, inner exception:  string: System.Exception: The application identifier provided is invalid.

Any idea what the problem is? The foreach loop only executes once because there's only one pinned secondary tile on my build. (Also I realize that UpdateSecondarySectionTile should take the tileId as a parameter and only update one tile per call; this is just debugging code.)

I find it interesting that it's complaining about the application identifier rather than the tile identifier. Also, I'm aware that tile updates sometimes do not work if you run them in the simulator, but I am encountering this issue even on my local machine.

user460847
  • 1,578
  • 6
  • 25
  • 43
  • 1
    Was the secondary tile initially pinned while running in the simulator? If you unpin the tile, and then repin it, is the same exception thrown? – Nathan Kuchta Nov 18 '12 at 00:11
  • Pulled your code verbatin into Scenario 8 of the [Secondary Tile Sample](http://code.msdn.microsoft.com/windowsapps/Secondary-Tiles-Sample-edf2a178) and it works fine. The id attribute for the tag isn't defined by the tile notification schema, but it's not a factor. You might try that same experiment and see if it fails, and if not, perhaps the problem is (somehow) elsewhere? – Jim O'Neil Nov 18 '12 at 01:51
  • Nathan Kuchta: I'm 90% sure that was the problem. It occurred to me before reading your comment, but I changed a few project settings as well. I'm on a company deadline so I really can't test right now--hopefully I'll have time to later. Thanks! – user460847 Nov 19 '12 at 17:18
  • Tested: yes, this was it. Thanks again! – user460847 Nov 21 '12 at 15:21

1 Answers1

3

The exception referenced in the question ("The application identifier provided is invalid") can be thrown by the CreateTileUpdaterForSecondaryTile method outside of the simulator if the secondary tile was initially pinned while in the simulator. To work around this issue, unpin the secondary tile and repin it outside of the simulator.

As noted by the question author, the tile update APIs (and other push notification related APIs) are not supported in the simulator. In this case, the secondary tile pinning was not persisted outside of the simulator.

Nathan Kuchta
  • 13,482
  • 2
  • 26
  • 35