Undebuggable crash launching from Cortana (or - how can I attach the debugger to my about-to-crash phone app?)

Hello,
I integrated voice activation for my WP8.1 universal app, however it doesn't appear to be possible to debug the case when starting the app afresh via Cortana with speech terms.
There are three main speech startup cases I've played with:
1) App is suspended - can be seen in multitasking list by holding down back button, go to Cortana "myapp do something" - reactivates the app, calls App.OnActivated.  Works fine.
2) App has been terminated - not in the multitasking list.  Go to Cortana "start myapp" - starts the app like it was launched from the app list, calls App.OnLaunched but not
OnActivated.  Works fine.
3) App has been terminated - not in the multitasking list.  Go to Cortana "myapp do something" - starts the app, comes through to App.OnActivate but the app hangs for a few seconds on
the splash screen and crashes (device and emulator).
I want to catch the 3) case in the debugger, but cannot find a way to attach the debugger to my running package in the time window between activation and crashing.  I think something is happening
deep in xaml land, but it's become impossible to instrument.  I'm actually at the point now where it doesn't do anything in the OnActivate handler at all... no page navigation happens in the app but it still crashes.
I have a debug dump showing what appears to be a divide-by-zero exception but I can't seem to debug it in VS2013 as it complains about skipping loading symbols for NGen'd exe and "The exception
thread has exited or the dump contains invalid thread information".
I cannot seem to find any information on how to effectively debug this scenario - it seems an important one for Cortana integration.
Basic repro:
In VS2013, create a new universal Hub app and editing the Windows Phone project:
Add Microphone capability in app manifest
Change the Display Name in the app manifest to something sayable.
Add in the most trivial speech activation capability using the VoiceCommandManager in App.OnLaunched with a very basic speech file.
Run once from the debugger to ensure everything is set up ok and voice command file is installed.
Kill from the debugger to make sure the app is terminated.
Hold down phone/emulator search button.
Say the phrase to start your app (in my case "CortanaCrashTest test something").
Cortana recognises the phrase and says it's going to start your app... app starts...
Sits on app splash screen, hang and crash.
Here are my code modifications:
Right at the top of App.OnLaunched:
#if WINDOWS_PHONE_APP
var storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Speech.xml"));
await Windows.Media.SpeechRecognition.VoiceCommandManager.InstallCommandSetsFromStorageFileAsync(storageFile);
#endif
Speech.xml (added to project as content):
<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
<CommandSet xml:lang="en-us" Name="test">
<Example>test stuff</Example>
<Command Name="test">
<Example>test stuff</Example>
<ListenFor>test {*}</ListenFor>
<Feedback>test...</Feedback>
<Navigate/>
</Command>
</CommandSet>
</VoiceCommands>
Thanks,
Will.

Hello,
I had the same problem and solved it.
This issue occurred because OnLaunched method is not called when the App is activated.
You have to copy some code from OnLaunched method in order to correct your problem.
OnActivated method must start with this code to correct your issue :
protected override void OnActivated(IActivatedEventArgs args)
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
rootFrame = new Frame();
rootFrame.CacheSize = 1;
Window.Current.Content = rootFrame;
rootFrame.Navigate(typeof(YourMainPage));
Window.Current.Activate();
// Your code here
Regards

Similar Messages

Maybe you are looking for