Skip to content

COMException -2147023728 when calling BackgroundTaskRegistration in MAUI WinUI project #27590

Open
@Mvk3aJKQh

Description

@Mvk3aJKQh

Description

I created both a brand new single and multi-app MAUI project, and added System.Diagnostics.Debug.WriteLine(Windows.ApplicationModel.Background.BackgroundTaskRegistration.AllTasks.Count); to the WinUI App constructor after InitializeComponent(); and it throws this exception. Works for .NET 8, but not for .NET 9. Creating the new project for .NET 8, then selecting .NET 9 for Windows prompts to install the Android SDKs when building.

Steps to Reproduce

  1. Create a new .NET 9 MAUI project
  2. Add System.Diagnostics.Debug.WriteLine(Windows.ApplicationModel.Background.BackgroundTaskRegistration.AllTasks.Count); to the WinUI App constructor after InitializeComponent();
  3. Run

Link to public reproduction project repository

https://github.com/Mvk3aJKQh/COMException-2147023728

Version with bug

9.0.14 SR1.4

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

.NET 8

Affected platforms

Windows

Affected platform versions

Windows 10 build 19045.5371

Did you find any workaround?

No response

Relevant log output

System.Runtime.InteropServices.COMException
  HResult=0x80070490
  Message=
  Source=WinRT.Runtime
  StackTrace:
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr)
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
   at ABI.Windows.ApplicationModel.Background.IBackgroundTaskRegistrationStaticsMethods.get_AllTasks(IObjectReference _obj)
   at Windows.ApplicationModel.Background.BackgroundTaskRegistration.get_AllTasks()
   at Product.Platforms.Windows.App..ctor() in {ProjectPath}\Platforms\Windows\App.xaml.cs:line 11
   at Product.Platforms.Windows.Program.<>c.<Main>b__0_0(ApplicationInitializationCallbackParams p) in {OutputPath}\obj\Debug\net9.0-windows10.0.19041.0\win10-x64\Platforms\Windows\App.g.i.cs:line 29
   at ABI.Microsoft.UI.Xaml.ApplicationInitializationCallback.Do_Abi_Invoke(IntPtr thisPtr, IntPtr p)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-architectureIssues with code structure, SDK structure, implementation detailsi/regressionThis issue described a confirmed regression on a currently supported versionplatform/windowsregressed-in-9.0.0s/move-to-vs-feedbackTells automation to ask the person to use VS Feedback to report the issues/needs-attentionIssue has more information and needs another looks/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions