-
Notifications
You must be signed in to change notification settings - Fork 371
Description
Describe the bug
When using UniversalBGTask from Windows App SDK, the backgroundtaskhost.exe
process crashes regularly. The actual background task is then never executed. Following crash stack:
PROCESS_NAME: backgroundTaskHost.exe
ERROR_CODE: (NTSTATUS) 0xc000027b - An application-internal exception has occurred.
# Child-SP RetAddr Call Site
00 00000044`de07e930 00007ffc`005b27bc biwinrt!Windows::ApplicationModel::Background::CBackgroundTaskInstance::ReportSilentException+0x6c [onecoreuap\base\background\bi\winrt\impl\actbwii.cpp @ 1072]
01 00000044`de07ef40 00007ffc`005b21d3 biwinrt!Windows::ApplicationModel::Background::CBackgroundTaskInstance::RunInternal+0x5cc [onecoreuap\base\background\bi\winrt\impl\actbwii.cpp @ 1012]
02 00000044`de07f140 00007ffc`2eb1de14 biwinrt!Windows::ApplicationModel::Background::CBackgroundTaskInstance::Run+0x53 [onecoreuap\base\background\bi\winrt\impl\actbwii.cpp @ 821]
03 00000044`de07f170 00007ffc`44050ce0 twinapi_appcore!Windows::ApplicationModel::Core::BackgroundTaskWrapper::ThreadProc+0xe4
04 00000044`de07f350 00007ffc`4403d7a1 ntdll!TppWorkpExecuteCallback+0x4d0
05 00000044`de07f4b0 00007ffc`4328e8d7 ntdll!TppWorkerThread+0x801
06 00000044`de07f810 00007ffc`4405c5dc kernel32!BaseThreadInitThunk+0x17
07 00000044`de07f840 00000000`00000000 ntdll!RtlUserThreadStart+0x2c
Stowed exception:
Stowed Exception #1 @ 0x000002145c1514c8
0x8007001F (FACILITY_WIN32 - Win32 Undecorated Error Codes): A device attached to the system is not functioning.
Stack : 0x2145c1538b0
7ffc422bb88f combase!RoOriginateLanguageException+0x5f
7ffc31c9400d Microsoft_Windows_ApplicationModel_Background_UniversalBGTask!winrt::hresult_error::originate+0x7d
7ffc31c942b3 Microsoft_Windows_ApplicationModel_Background_UniversalBGTask!winrt::hresult_error::hresult_error+0x1cb
7ffc31c94543 Microsoft_Windows_ApplicationModel_Background_UniversalBGTask!winrt::throw_hresult+0x213
7ffc31c914ef Microsoft_Windows_ApplicationModel_Background_UniversalBGTask!winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::implementation::Task::Run+0x463
7ffc31c91a5c Microsoft_Windows_ApplicationModel_Background_UniversalBGTask!winrt::impl::produce<winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::implementation::Task,winrt::Windows::ApplicationModel::Background::IBackgroundTask>::Run+0x2c
7ffc005b23c1 biwinrt!Windows::ApplicationModel::Background::CBackgroundTaskInstance::RunInternal+0x1d1
7ffc005b21d3 biwinrt!Windows::ApplicationModel::Background::CBackgroundTaskInstance::Run+0x53
7ffc2eb1de14 twinapi_appcore!Windows::ApplicationModel::Core::BackgroundTaskWrapper::ThreadProc+0xe4
7ffc44050ce0 ntdll!TppWorkpExecuteCallback+0x4d0
7ffc4403d7a1 ntdll!TppWorkerThread+0x801
7ffc4328e8d7 kernel32!BaseThreadInitThunk+0x17
7ffc4405c5dc ntdll!RtlUserThreadStart+0x2c
When checking the offset with the source file, the error seems to be at the lookup of the ApplicationData.Values
:
(00000001`8000108c) Microsoft_Windows_ApplicationModel_Background_UniversalBGTask!winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTask::implementation::Task::Run+0x463 | (00000001`800015a0) Microsoft_Windows_ApplicationModel_Background_UniversalBGTask!winrt::impl::consume_Windows_Foundation_Collections_IMap<winrt::Windows::Foundation::Collections::IPropertySet,winrt::hstring,winrt::Windows::Foundation::IInspectable>::Lookup
When trying to execute similar lookup code in the packaged WinUI 3 app itself (using the TaskID as lookup value, found via PowerShell Get-AppBackgroundTask
), no crash occurs and the CLSID is returned as expected.
Full dump file can be provided privately if required.
Steps to reproduce the bug
The exact conditions to reproduce are unclear. It seems to only happen if the main app isn't currently running while the background task is being started. When starting the background task via Visual Studio "Lifecycle Events", no error occurs.
- Define COM server extension for background task in appxmanifest
<com:Extension Category="windows.comServer">
<com:ComServer>
<!-- COM Server for the background task, LaunchAndActivationPermission is required to give permission
for backgroundtaskhost process to cocreate this COM component -->
<com:ExeServer Executable="myapp.exe" Arguments="-RegisterForBGTaskServer" DisplayName="BackgroundTask"
LaunchAndActivationPermission="O:PSG:BUD:(A;;11;;;IU)(A;;11;;;S-1-15-2-1)S:(ML;;NX;;;LW)">
<com:Class Id="918674B4-E2FF-4041-B23F-568F6B897473" DisplayName="myTask" />
</com:ExeServer>
</com:ComServer>
</com:Extension>
- Register background task with
Microsoft.Windows.ApplicationModel.Background.BackgroundTaskBuilder
andSetTaskEntryPointClsid(918674B4-E2FF-4041-B23F-568F6B897473)
- Run the app once to register everything
- Close the app (+restart the PC?)
- Get background task ID with
Get-AppBackgroundTask
in PowerShell - Start background task with
Start-AppBackgroundTask -TaskID ...
in PowerShell - Check crash dump file in
%localappdata%\CrashDumps
Expected behavior
backgroundtaskhost.exe
process doesn't crash.
Screenshots
No response
NuGet package version
Windows App SDK 1.7.3: 1.7.250606001
Packaging type
Packaged (MSIX)
Windows version
Windows 11 version 24H2 (26100, June 2025 Update)
IDE
Visual Studio 2022
Additional context
No response