C# 正在尝试从Windows Phone 8.1中的backgroundaudiotask更新livetile:“;提供的应用程序标识符无效";

C# 正在尝试从Windows Phone 8.1中的backgroundaudiotask更新livetile:“;提供的应用程序标识符无效";,c#,windows-8,windows-8.1,windows-phone-8.1,live-tile,C#,Windows 8,Windows 8.1,Windows Phone 8.1,Live Tile,我有一个音乐播放器,想用播放曲目的专辑艺术更新livetile。因此,每次轨迹发生变化时,我都在单独的Windows Runtine组件中调用一个方法。方法如下所示: public async void CreateLivetile(string albumart, string artist, string trackname) { try { // constants string textElementName = "text";

我有一个音乐播放器,想用播放曲目的专辑艺术更新livetile。因此,每次轨迹发生变化时,我都在单独的Windows Runtine组件中调用一个方法。方法如下所示:

public async void CreateLivetile(string albumart, string artist, string trackname)
{
    try
    {
        // constants
        string textElementName = "text";
        string imageElementName = "image";

        // Create a tile update manager
        var updater = TileUpdateManager.CreateTileUpdaterForApplication();
        updater.EnableNotificationQueue(true);
        updater.Clear();

        // wide 310x150
        var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150PeekImage03);
        tileXml.GetElementsByTagName(textElementName).LastOrDefault().InnerText = string.Format(artist + " - " + trackname);
        var image = tileXml.GetElementsByTagName(imageElementName).FirstOrDefault();
        if (image != null)
        {
            var src = tileXml.CreateAttribute("src");
            src.Value = albumart;
            image.Attributes.SetNamedItem(src);
        }

        // square 150x150
        var squaredTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText01);
        squaredTileXml.GetElementsByTagName(textElementName).FirstOrDefault().InnerText = string.Format(artist + " - " + trackname);
        image = squaredTileXml.GetElementsByTagName(imageElementName).LastOrDefault();
        if (image != null)
        {
            var src = squaredTileXml.CreateAttribute("src");
            src.Value = albumart;
            image.Attributes.SetNamedItem(src);
        }

        updater.Update(new TileNotification(tileXml));
        updater.Update(new TileNotification(squaredTileXml));
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);

        // Inform the system that the task is finished.
        //_deferral.Complete();
    }
}
当方法到达此行时:

var updater = TileUpdateManager.CreateTileUpdaterForApplication();
我得到这个错误:

The application identifier provided is invalid.

此方法在应用程序(前端)中运行良好。

您在模拟器中发现了一个常见错误

发件人:

我们发现了导致此故障的两种情况。第一个是在 在Visual Studio中的模拟器中运行应用程序时的应用程序开发 演播室更新分幅时可能会引发此错误。这个 建议在本地计算机设置下运行应用程序 [……]

其次,当底层通知 平台在用户的计算机上不可用。如果通知 平台遇到导致其终止的问题,它 也会导致磁贴通知和更新失败。呼吁
TileUpdateManager.CreateTileUpdateForApplication
通常检索 包的全名,创建通知端点,并执行 通知子系统的包和应用程序名称验证。 最后两个步骤中的任何一个出现问题都可能导致“应用程序失败” 提供的标识符无效,将返回,生成此 例外

另见:

    • 有解决方案:

      直接提供身份证即可:
      TileUpdateManager.createTileUpdateForApplication(“应用程序”)

      我忘了提到它是一个Windows Phone 8.1应用程序。当我没有调试时,它也不起作用:/。@PhilippeMaes-当把这个方法放在我的主应用程序中时,你能澄清一下“这个方法在应用程序(前端)中工作得很好…”。因此,在任何后台任务或额外项目中都不会出现此错误。仅供参考,在设备上调试时也会出现此错误。不只是降级到模拟器。您必须提供您的应用程序的名称。当前实例使其消失-“应用程序”通常。您好!你解决这个问题了吗?我也有同样的例外。。。不,我没有找到解决方案:/Please: