我正在尝试将cortana语音命令添加到我的应用中。但是,当我尝试安装语音命令定义时,我得到了COMException“DiePaketidentitätistbeschädigt”(包ID被破坏)。
我将语音命令定义文件减少到最小,但没有效果。我的代码是:
private static async Task InstallVoiceCommandsIfNecessary()
{
#if WINDOWS_UWP
var installed = Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey("VoiceCommandsInstalled");
if (!installed)
{
try
{
var storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(
new Uri("ms-appx:///Cortana/VoiceCommands.xml"));
await Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinitionManager.
InstallCommandDefinitionsFromStorageFileAsync(storageFile);
// The line above is throwing the exception ----^
Windows.Storage.ApplicationData.Current.LocalSettings.Values["VoiceCommandsInstalled"] = true;
}
catch (Exception) { }
}
#endif
}
来自OnLaunched。
VoiceCommands.xml:
<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-us" Name="StopNowCommandSet_en-us">
<AppName>Stopnow</AppName>
<Example> stop a time </Example>
<Command Name="stopWatch">
<Example> stop a time </Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> stop [a] time [in] </ListenFor>
<Feedback> Launching the stopwatch </Feedback>
<Navigate/>
</Command>
</CommandSet>
</VoiceCommands>
我在InstallCommandDefinitionsFromStorageFileAsync上放了一个断点,GetFileFromApplicationUriAsync成功了。
问题似乎是InstallCommandDefinitionsFromStorageFileAsync调用。
更新
相同的代码适用于Windows 10移动模拟器。这可能是本地安装问题吗?