Forum Discussion
Winforms .exe in MSIX Package Does Not Startup After Auto Update
https://techcommunity.microsoft.com/t5/msix-deployment/what-is-the-quot-gap-quot-and-how-do-i-eliminate-it/m-p/2873569
The symptoms I see are identical to what you guys are seeing. The app will appear, but it needs to be prodded along or sometimes it just appears by itself.
A bit more info:
- I got Windows into a state where I could reproduce this 100% of the time. The AppInstaller XML used was below.
- The AI log showed no problems, which isn't a surprise as the bug seems to be in the start/taskbar code.
- I didn't see my app EXE in task manager, not as a background task or anything else, and disabling background tasks makes no difference.
- Although I thought this was related to the "gap" in the AppxDeploymentServer logs, I can reproduce this also without any large values in the gap timings.
- In fact there is no timing issue involved here, even though it seemed that way at first. Careful testing shows that in my case, the app will never start until the start menu or search bar is interacted with, at which point it starts immediately. Interacting with other parts of the taskbar doesn't trigger this. It doesn't matter how long I wait after an upgrade - if I don't touch search or start button, the app will not launch after an upgrade.
- If I open the start menu I don't have to re-launch my app from there or do anything else. The mere act of clicking on it will cause the app to launch, and in fact, when it does it will steal focus and thus the start menu will disappear again.
- However after changing my AppInstaller XML to disable the prompt, doing a couple of upgrades, and then changing it back the problem has gone away. Now Windows starts the app after an upgrade successfully. To me this smells like another caching bug: perhaps Windows isn't handling changes to the OnLaunch settings properly and the taskbar/AppInstaller components can get confused about what update modes the app is meant to be using?
XML:
<OnLaunch HoursBetweenUpdateChecks="0" ShowPrompt="true" UpdateBlocksActivation="true"/>
<AutomaticBackgroundTask />
<ForceUpdateFromAnyVersion>true</ForceUpdateFromAnyVersion>
I noticed from reading the documentation that the way App Installer is invoked doesn't seem very deeply integrated with Windows. Supposedly the upgrade check is done only if the taskbar is used to launch the app. If you have e.g. a shortcut on your desktop, and use that, then App Installer doesn't get involved at all. Or if any other process starts your app, same thing, the update check isn't done.
Therefore what seems to be happening is something like this:
- The taskbar/start menu code is asked to launch an app controlled by AppInstaller.
- It consults its timeout list and notices it's time to do an update check.
- It passes control to App Installer to do the update and waits for a signal that the update has been completed.
- AI sends that signal (somehow).
- Something goes wrong: the Start code has been put to sleep in a way that it doesn't wake up when the signal arrives.
- Interacting with the taskbar in such a way that the list of app icons is pulled up, re-awakens that part of the code, which then notices the signal from App Installer and continues with the launch of the app.
This doesn't happen on every code path. If an update check is done but no update is required, the launch works OK (but that might be a timing-caused red herring?).
A workaround is to disable the prompt using ShowPrompt="false" and go to fully silent upgrades i.e. with background upgrades only. This means that if an update has just been released and the user starts their app, it will be the old version and the next start will be upgraded, but, this is only a short window of time as after 8 hours Windows will (supposedly) apply the upgrade in the background anyway. Fully silent upgrades are what Chrome uses so this is an acceptable workaround for now - it is only an issue if the app needs to be forcibly upgraded to match e.g. a protocol change on a server.
In that case the app itself may need to figure out by itself if it's fully up to date or not and if not, restart itself to re-load the updated code - possibly monitoring the AppX logs to figure out when Windows has finished applying the upgrade.
- Lars_PedersenOct 25, 2021Copper ContributorGreat investigation. Someone should start a support case with Microsoft so the bug will find its way into their systems and get more attention.
My workaround would probably be to restart the app after detecting a pending update.- MikeHOct 25, 2021Brass Contributor
Lars_Pedersen I'm afraid I don't know how to open a formal support case. Does anyone have any experience with that?