Repository navigation
Description
Describe the bug
I added support for background tasks as described in the documentation: https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/applifecycle/background-tasks
It works for most users, but I am seeing a lot of crash reports (in the Partner Center) for all my apps published in the Microsoft Store that are using background tasks.
With WinAppSDK 1.7, it was mostly ACCESS_VIOLATION errors and they have been discussed in this issue (which for some reason has been moved to the microsoft/microsoft-ui-xaml repository).
Now, after upgrading to WinAppSDK 1.8, I am still seeing crashes (seemingly the same amount - way over 10.000 crashes per day!), but with error code STOWED_EXCEPTION. Since the amount of crashes exceeds the "devices affected", it looks like the crash is happening repeatedly for the same machines.
Here are some stack traces as reported by the Microsoft Partner Center:
STOWED_EXCEPTION_80004005_Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll!_CallSettingFrame_LookupContinuationIndex
Frame Image Function
0 combase.dll RoOriginateLanguageException
1 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::hresult_error::originate
2 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll `winrt::to_hresult'::`1'::catch$23
3 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll _CallSettingFrame_LookupContinuationIndex
4 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll __FrameHandler4::CxxCallCatchBlock
5 ntdll.dll RcFrameConsolidation
6 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::to_hresult
7 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll `winrt::impl::root_implements_winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::factory_implementation::Task,winrt::Windows::Foundation::IActivationFactory_::NonDelegatingGetTrustLevel'::`1'::catch$0
8 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll _CallSettingFrame_LookupContinuationIndex
9 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll __FrameHandler4::CxxCallCatchBlock
10 ntdll.dll RcFrameConsolidation
11 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::impl::produce_winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::implementation::Task,winrt::Windows::ApplicationModel::Background::IBackgroundTask_::Run
12 biwinrt.dll Windows::ApplicationModel::Background::CBackgroundTaskInstance::RunInternal
13 biwinrt.dll Windows::ApplicationModel::Background::CBackgroundTaskInstance::Run
14 twinapi.appcore.dll Windows::ApplicationModel::Core::BackgroundTaskWrapper::ThreadProc
15 ntdll.dll TppWorkpExecuteCallback
16 ntdll.dll TppWorkerThread
17 kernel32.dll BaseThreadInitThunk
18 ntdll.dll RtlUserThreadStart
STOWED_EXCEPTION_80004002_Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll!winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::implementation::Task::Run
Frame Image Function
0 combase.dll RoOriginateLanguageException
1 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::hresult_error::originate
2 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::hresult_no_interface::hresult_no_interface
3 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::implementation::Task::Run
4 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::impl::produce_winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::implementation::Task,winrt::Windows::ApplicationModel::Background::IBackgroundTask_::Run
5 biwinrt.dll Windows::ApplicationModel::Background::CBackgroundTaskInstance::RunInternal
6 biwinrt.dll Windows::ApplicationModel::Background::CBackgroundTaskInstance::Run
7 twinapi.appcore.dll Windows::ApplicationModel::Core::BackgroundTaskWrapper::ThreadProc
8 ntdll.dll TppWorkpExecuteCallback
9 ntdll.dll TppWorkerThread
10 kernel32.dll BaseThreadInitThunk
11 ntdll.dll RtlUserThreadStart
STOWED_EXCEPTION_80004005_Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll!Unknown
Frame Image Function
0 combase.dll RoOriginateLanguageException
1 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll -
2 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll -
3 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll -
4 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll -
5 ntdll.dll RcFrameConsolidation
6 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll -
7 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll -
8 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll -
9 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll -
10 ntdll.dll RcFrameConsolidation
11 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll -
12 biwinrt.dll -
13 biwinrt.dll -
14 twinapi.appcore.dll Windows::ApplicationModel::Core::BackgroundTaskWrapper::ThreadProc
15 ntdll.dll TppWorkpExecuteCallback
16 ntdll.dll TppWorkerThread
17 kernel32.dll BaseThreadInitThunk
18 ntdll.dll RtlUserThreadStart
STOWED_EXCEPTION_800706ba_Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll!winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::implementation::Task::Run
Frame Image Function
0 combase.dll RoOriginateLanguageException
1 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::hresult_error::originate
2 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::hresult_error::hresult_error
3 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::throw_hresult
4 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::implementation::Task::Run
5 Microsoft.Windows.ApplicationModel.Background.UniversalBGTask.dll winrt::impl::produce_winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::implementation::Task,winrt::Windows::ApplicationModel::Background::IBackgroundTask_::Run
6 biwinrt.dll Windows::ApplicationModel::Background::CBackgroundTaskInstance::RunInternal
7 biwinrt.dll Windows::ApplicationModel::Background::CBackgroundTaskInstance::Run
8 twinapi.appcore.dll Windows::ApplicationModel::Core::BackgroundTaskWrapper::Run
9 twinapi.appcore.dll Windows::ApplicationModel::Core::BackgroundTaskWrapper::ThreadProc
10 ntdll.dll TppWorkpExecuteCallback
11 ntdll.dll TppWorkerThread
12 kernel32.dll BaseThreadInitThunk
13 ntdll.dll RtlUserThreadStart
NuGet package version
Windows App SDK 1.8.1: 1.8.250916003
Packaging type
Packaged (MSIX)
Windows version
Windows 11 version 24H2 LTSC (26100, June Update)
IDE
Visual Studio 2022
Additional context
Crashes happen on various Windows versions, e.g. Windows 11 10.0.26100, Windows 11 10.0.22631, Windows 10 10.0.19045, ...
Activity
godlytalias commentedon Oct 14, 2025
I had a look into these crash dumps, and the crash is happening as
CoCreateInstancefails and throws exception. On further checking the etl files, below are some relevant ones I am seeingCan you once check whether the
LaunchAndActivationPermissionsare set appropriately as done in the sample heretipa commentedon Oct 14, 2025
Yes,
LaunchAndActivationPermissionsis set exactly like that.I think the background task is working as intended for most users, and if
LaunchAndActivationPermissionswasn't set properly, it wouldn't work for any?tipa commentedon Oct 22, 2025
Godly T.Alias (@godlytalias) please let me know if you need any additional information from me.
Is it possible that crash happens when the WinAppSDK Runtime hasn't been properly installed alongside WorkingHours? Or has been uninstalled forcefully later on? I've heard from instances where this happened.
For one of my apps I am now seeing almost 15.000 (!) crashes per day - and it's still an upwards trend
godlytalias commentedon Oct 22, 2025
Timo Partl (@tipa) Its not related to WinAppSDK Runtime, I can see the UniversalBGTask operations being executed, but the above COM class IDs mentioned is from your app right? Errors say that the
CoCreateInstancefor these COM classes fail as it is not found in the package.Howard Kapustein (@DrusTheAxe) Whether you have any clue on why these package related errors happen, #5870 (comment)
tipa commentedon Oct 22, 2025
Godly T.Alias (@godlytalias) Yes, that is the GUID for my background task. It's certainly in the app, you can test it yourself :) As I said, from what I can tell the background task basically works for most users.
Isn't there a way to handle this error in your code so that it doesn't crash my app?
godlytalias commentedon Oct 22, 2025
Timo Partl (@tipa) Ignoring
CoCreateInstancefailures would be problematic, In that case we may not be able to know of real issues where the tasks are not running. Right path here would be to identify the issue with the package here and get it fixed. Anyway user experience would be same in this case as well as if we simply ignore the failure. Crash would be for backgroundtaskhost.exe process, not the app processtipa commentedon Oct 22, 2025
Godly T.Alias (@godlytalias) I'd totally prefer if you could find the underlying issue, but from a developer perspective handling or not handling the error does make a difference. At the moment, my crash reporting in the Partner Center is totally flooded with those crashes and it makes it so much harder to identify the crashes I am actually able to fix. Additionally, getting so many crashes can have an impact on the Store ranking algorithm and potentially cause my app to become less visible in the Store.
Would this crash happen when not calling
CoRegisterClassObject?I've identified many cases in which my app throws an exception on startup (caused by the WinAppSDK - I've already reported them here). I am currently catching those errors and gracefully exit the app, without calling
CoRegisterClassObject(I call that method in myApps constructor).godlytalias commentedon Oct 22, 2025
If the COM server don't do
CoRegisterClassObject, that would fail theCoCreateInstancefor sure. But I am not sure whether that is the only cause for crashes here.Howard Kapustein (@DrusTheAxe) may have some clues from package deployment perspective.
tipa commentedon Oct 31, 2025
I made sure to call
CoRegisterClassObjectbefore anything else in my app, as first instruction in theProgram.Main()method (I'm using a single-instanced app, if that's of relevance here) - without luck.I have found yet another oddity with this background task implementation. When I omit
RuntimeIdentifierin mycsprojfile, the background task just never fires, and I also don't see a crash. Why?Going through the sample, I also noted this line in which
ComServer.CoRevokeObjectis called. Is this of importance? If yes, why and if no, why is it included in the sample?Same question about this part. Is
WindowsAppSDKBackgroundTask=truein the csproj really required? It seems to work without it in my apps. Why is it documented as being required?In the meatime, my crash count keeps rising every day and since there doesn't seem to be any fix on the horizon, I will at some point have to consider to remove the entire background task from my app again.
godlytalias commentedon Oct 31, 2025
If you omit
RuntimeIdentifier, I guess it may not be deploying theuniversalbgtask.dllas well, you can see whether the dll is getting included in the package. Also about the point 'seeing a crash', these crashes in the spikes are from backgroundtaskhost.exe, which would not crash the 'main application process'. I think you may have to look into 'Diagnostic Data Viewer' -> Problem Reports tab / search forMicrosoft.Windows.BrokerInfrastructure.*telemetry to see what is the status of the tasks (If that is not the way you're checking crash).ComServer.CoRevokeObjectdoes the cleanup operations when COM server shuts down, so that COM doesn't call into a dead server handle. This may be required when application closes. This can be a catch if not being done.WindowsAppSDKBackgroundTask=trueis not required for C# projects, as the binaries gets placed during publish operations otherwise as well. Its required for cppwinrt projects only.If you're having so much crash count, there should be some way to repro the issue, if you can share a repro, it would be easy to figure out root cause (as mentioned above you should not be looking for the app process crashing, it would be backgroundtaskhost.exe which would be crashing). From the crash dumps what I can find out is that, the COM server looks for creating instance of the background task class registered, but that fails.
tipa commentedon Oct 31, 2025
When I'm referring to a "crash" then I mean a "Crash" as reported by the Partner Center in the "Health" tab and these are a problem for me.
I don't think these crashes are coming from my machines, so I won't be able to gather contextual information in the Diagnostic Data Viewer. Searching for
Microsoft.Windows.BrokerInfrastructure.*yields no results.internaland it works as expected - why? Or is this even the correct documentation for my case? It contains code aboutRegistrationServicesthat is nowhere to be found in the example app. It is really confusingCoRegisterClassObjectapproach to integrate into the Windows widget panel, and that component doesn't crash at all - at least I see no related crash reports in the Partner CenterCoRevokeObjectand report back if that changes things, but I don't have much hope to be honest, given all my previous changes didn't improve the situation either. If using this method is really required, why is it not documented anywhere, only used in the example project? Additionally, from what I can tell basd on a few quick tests, the App deconstructor is never called.Would you agree that the sample should be fixed then? It currently is in the C# project sample with the note
This tag is required for the usage of WinAppSDK Background Task APIAs I wrote before, I don't think the crashes originate from my machine, nor from machines of the majority of users. The Partner Center reports that the 15.000 crashes originate from just 460 devices (and I have much more daily active users). So that makes 32 crashes per devices on an average day. I am using a background task with a 15 minute
TimeTrigger- that would perfectly match a regular 8 hour work day (4 crashes per hour)What I can do is share a trimmed down example project that shows how I have implemented the background task. Would that help?
godlytalias commentedon Oct 31, 2025
You're referring to the Platform SDK Documentation which have been there for quite some time. I don't have the context of all those points. However I feel its fair point that the background task class need to be public as it need to be invoked by an external component.
CoRevokeClassObjectis required however, I can see that in the sample as well in the doc link you shared, More details can be seen in theCoRevokeClassObjectdocs as well, https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-corevokeclassobject (notCoRevokeObject, winappsdk sample to be fixed)WindowsAppSDKBackgroundTask=trueis to be fixed in C# case from winappsdk targets file itself, Currently it is working through C# publishing mechanism, hence even the apps that don't require background task ends up having those universalbgtask binaries. In upcoming versions this need to be fixed that only apps which have this flag will have those binaries packaged.I would suggest to fix the
revokeoperation and once see whether crash count goes downtipa commentedon Oct 31, 2025
Thanks for the quick response.
It's a bit irritating that there's a documented need for the class to be
public, but it appears to be working even when the visibility isinternal. Shouldn't it not work at all if it's internal? Well I'll make it public and also call theCoRevokeClassObjectmethod and report back in a few days! I will also try to prepare a sample project that shows how I implemented the background task in my app.When using the single-instanced app model, should I be calling
CoRevokeClassObjectin the Main method as seend below instead of the Apps constructor?25 remaining items
tipa commentedon May 21, 2026
Thanks. Could you clarify what exactly you mean by “ApplicationData got cleaned up”?
Should I check whether
ApplicationData.Current.LocalSettingsis empty, whetherLocalFolderis empty, or is there another package/AppData state I can reliably query?I can unregister background tasks when app data appears empty and old registrations still exist, but that only helps if my app process actually gets launched. If the crash happens inside
backgroundTaskHost.exe/UniversalBGTaskbefore my EXE gets control, app-side cleanup cannot run.Is this workaround expected to help in that pre-app-start crash case too?
godlytalias commentedon May 25, 2026
Yes,
ApplicationData.Current.LocalSettingscan be checked whether it is empty and clear up the registration. We can run this task in the UWP background task itself (as a maintenance trigger or servicing complete trigger) so that UniversalBGTask is not involved.This can be an improvement done to UniversalBGTask itself to clear up the registration if the LocalSettings have gone empty I think.
tipa commentedon May 25, 2026
Thanks, that clarifies it.
If
UniversalBGTaskcan checkApplicationData.Current.LocalSettingsand unregister stale background task registrations before attempting COM activation, that sounds like the right place for this mitigation. An app-side workaround can only run after my EXE gets control, so it cannot help whenbackgroundTaskHost.exe/UniversalBGTaskcrashes before COM activation succeeds.For an app-side workaround: should I only check
ApplicationData.Current.LocalSettings.Values.Count == 0, or should I also check for missing app-owned settings keys? IfLocalSettingswas cleaned and the app later started normally, it may recreate default settings, soLocalSettingswould no longer be empty even though the cleanup already happened.Is there any other workaround you recommend that app developers can apply today, or should this mainly be fixed in
UniversalBGTask?godlytalias commentedon May 26, 2026
TaskId-Com GUIDpropertyset is what is expected in theLocalSettingsfor the lookup to work properly.Workaround can be done from app side now with the UWP Background Task as I mentioned earlier (Setup a WinRT component and give that as entry point using
Windows.ApplicationModel.BackgroundTaskAPIs for aServiceCompleteorMaintenancetrigger). These tasks would get executed outside theUniversalBGTaskand can be leveraged to check the correctness ofApplicationData.tipa commentedon May 26, 2026
Thanks. Given that the missing
TaskId -> COM GUIDmapping is state required byUniversalBGTask, and the crash happens insideUniversalBGTaskbefore my app may get control, it sounds like the robust fix would need to be inUniversalBGTaskitself.I can add app-side cleanup, but that cannot reliably stop the crash loop if COM activation fails before my EXE starts. Also, adding a separate WinRT/UWP cleanup background task to every affected app is quite a large workaround for state that is internal to the WinAppSDK background task bridge. I’ve already had to add several app-side mitigations around this area, and none can cover failures that happen before the app process starts.
Is there anything preventing
UniversalBGTaskfrom detecting the missing mapping and unregistering/aborting cleanly before it throws?godlytalias commentedon May 26, 2026
I've created the PR here: #6507
It may take some time to get merged and serviced probably. Meanwhile if you want you can try the app workaround.
tipa commentedon May 26, 2026
Thanks, this looks like the right place to handle it. I’ll keep my lightweight app-side cleanup/telemetry for now, but I’ll avoid adding the separate UWP cleanup task unless the PR takes too long to ship.
Do you already know which WinAppSDK version this is expected to be serviced in?
godlytalias commentedon May 27, 2026
Will plan to service in 1.8 & 2.0, However it may require a rebuild and update of app post that as this DLL is bundled with app package.
chore(deps): update dependency microsoft.windowsappsdk to 2.3.1 (#4406)
tipa commentedon Aug 4, 2026
Thanks a lot for the fix and the latest release! After updating to Runtime 2.3.1, Partner Center shows substantially fewer crashes but a sharp increase in hangs, without relevant app-side changes. One current release reports 288
HANG_QUIESCEevents on 284 devices.Another affected release still reports
UniversalBGTask::Task::Runcrashes with0x80073DB8(ERROR_STATE_LOAD_STORE_FAILED). The current implementation accessesApplicationData::Current().LocalSettings()before the guarded missing-key path, without handling state-store loading failures. Could the exception be escaping there?Could you check the Store-side diagnostics and whether the increased hangs are related?
Also, is the elevated/per-user COM activation limitation mentioned earlier still applicable after #6507, and is it tracked separately?
godlytalias commentedon Aug 4, 2026
HANG_QUIESCEhappens if the background task don't finish in the allowed time interval, The process would be terminated / suspended once the time runs out. Holding the deferral can increase the time window. Elevated COM activation is still applicable as the current changes was just for graciously handling some of the common crash cases.Tagging Howard Kapustein (@DrusTheAxe) for
0x80073DB8on ApplicationData.