Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mvk3aJKQh opened this issue Feb 6, 2025 · 8 comments
Labels
area-architecture Issues with code structure, SDK structure, implementation details i/regression This issue described a confirmed regression on a currently supported version platform/windows 🪟 regressed-in-9.0.0 s/move-to-vs-feedback Tells automation to ask the person to use VS Feedback to report the issue s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@Mvk3aJKQh
Copy link

Mvk3aJKQh commented Feb 6, 2025

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)
@Mvk3aJKQh Mvk3aJKQh added the t/bug Something isn't working label Feb 6, 2025
@jfversluis jfversluis added platform/windows 🪟 s/needs-repro Attach a solution or code which reproduces the issue labels Feb 6, 2025
@Mvk3aJKQh
Copy link
Author

Added link to repository

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Feb 8, 2025
@RoiChen001 RoiChen001 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Feb 8, 2025
@RoiChen001
Copy link

RoiChen001 commented Feb 8, 2025

I can repro this issue at Windows platform on the latest 17.13 Preview 5(9.0.30 & 9.0.14), but the exception does not exist in 8.0.100.

Image

@RoiChen001 RoiChen001 added the i/regression This issue described a confirmed regression on a currently supported version label Feb 8, 2025
@mattleibow
Copy link
Member

mattleibow commented Feb 10, 2025

Is this a packaged or unpackaged app?

Seems to be this: microsoft/WindowsAppSDK#4201

Even this: microsoft/CsWinRT#1518

@mattleibow
Copy link
Member

@RoiChen001 are you able to use .net 8 and upgrade the Windows App SDK to the latest?

@mattleibow
Copy link
Member

Does this happen on Windows 11 AND Windows 10?

@PureWeen PureWeen added s/needs-info Issue needs more info from the author regressed-in-9.0.0 area-architecture Issues with code structure, SDK structure, implementation details and removed s/needs-attention Issue has more information and needs another look labels Feb 10, 2025
@Mvk3aJKQh
Copy link
Author

Looks like a problem with the WindowsPackageType element in the project file. In a new .NET 8 project, this element isn't required, though the properties UI has the "Create a Windows MSIX package." option already selected. When I deselect this option, same exception occurs. In a new .NET 9 project, this element is required, already present, and removing it from the project file will cause a different exception. This option is not already selected in the properties UI, and selecting it changes the value of the WindowsPackageType element from "None" to "MSIX". And this corrects the problem raised in this issue.

In the new .NET 8 project, deselecting the "Create a Windows MSIX package." option adds the WindowsPackageType element to the project file with a value of "None". This results in the same exception raised in this issue. Reselecting this option then changes the value of this element to "MSIX". However, this element can be removed from the .NET 8 project file without causing an exception.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Feb 13, 2025
@PureWeen PureWeen added the s/move-to-vs-feedback Tells automation to ask the person to use VS Feedback to report the issue label Feb 13, 2025
Copy link
Contributor

Thanks for the issue report @Mvk3aJKQh! This issue appears to be a problem with Visual Studio, so we ask that you use the VS feedback tool to report the issue. That way it will get to the routed to the team that owns this experience in VS.

If you encounter a problem with Visual Studio, we want to know about it so that we can diagnose and fix it. By using the Report a Problem tool, you can collect detailed information about the problem, and send it to Microsoft with just a few button clicks.

  1. Go to the Visual Studio for Windows feedback tool or Visual Studio for Mac feedback tool to report the issue
  2. Close this bug, and consider adding a link to the VS Feedback issue so that others can follow its activity there.

@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2025
@Mvk3aJKQh
Copy link
Author

Mvk3aJKQh commented Feb 13, 2025

Well I can't find information about whether (MSIX) packaging is required to use WinRT. The exception suggests that it is required, since a value of "None" causes the exception in both projects. This would seem to be an issue with an API, and not Visual Studio. The properties UI in Visual Studio does something different between newly created .NET 8 and .NET 9 projects, but the issue is the same when deselecting the "Create a Windows MSIX package." option in the .NET 8 project. So we still have a requirement to create an MSIX package to access the Windows.ApplicationModel.Background namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-architecture Issues with code structure, SDK structure, implementation details i/regression This issue described a confirmed regression on a currently supported version platform/windows 🪟 regressed-in-9.0.0 s/move-to-vs-feedback Tells automation to ask the person to use VS Feedback to report the issue s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants