microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.85k stars 328 forks source link

REGDB_E_CLASSNOTREG on AppNotificationManager.Default.Register() for packaged App. #2894

Open DexterWoo opened 2 years ago

DexterWoo commented 2 years ago

Describe the bug

I recently created a packaged app with WindowsAppSDK. on my test system, it crashes every time AppNotificationManager.Default.Register() is invoked,

Exception Info: System.Runtime.InteropServices.COMException (0x80040154): Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
   at ABI.Microsoft.Windows.AppNotifications.IAppNotificationManagerMethods.Register(IObjectReference _obj)
   at Microsoft.Windows.AppNotifications.AppNotificationManager.Register()
   at WindowsAppSDKEvaluation.Program.Main(String[] args)

tested with 1.1.2,and 1.1.4, all same exception.

Steps to reproduce the bug

Install the packaged app, and launch.

Expected behavior

Launch and enter UI.

Screenshots

No response

NuGet package version

1.1.4

Packaging type

Packaged (MSIX)

Windows version

Windows 10 version 1903 (18362, May 2019 Update)

IDE

Visual Studio 2022

Additional context

No response

DarranRowe commented 2 years ago

Did you follow the quick start? The error does appear to be that the application is trying to access the COM server registration but isn't able to find it.

The output (C++ output here) was very descriptive. Just trying to get the default AppNotificationManager results in the output: Microsoft.WindowsAppRuntime.dll!00007FFAD11953D6: ReturnHr(1) tid(4198) 80004005 Unspecified error Msg:[D:\a\_work\1\s\dev\PushNotifications\PushNotificationUtility.h(188)\Microsoft.WindowsAppRuntime.dll!00007FFAD1139EC2: (caller: 00007FFAD1147EF8) Exception(1) tid(4198) 80004005 Unspecified error Msg:[No COM servers are registered for this app] ] Looking at PushNotificationUtility.h line 188, which is available in the repository, shows that the code is trying to read the Com server from the registry and failing. So could you make sure that you have fully followed the quick start, and could you see if you can get this output from your application?

DexterWoo commented 2 years ago

this happens randomly, only some of our QA's system have such issues. I switched to Microsoft.Toolkit.Uwp.Notifications just so that we can proceed with our project.

pmpurifoy commented 2 years ago

Can you verify that the Singleton package has been installed as well?

DexterWoo commented 2 years ago

I just confirmed on the system and find that Microsoft.WindowsAppRuntime.Singleton is indeed not installed on the system.

checked the document on https://docs.microsoft.com/en-us/windows/apps/windows-app-sdk/deployment-architecture I just cannot figure out how to declare Microsoft.WindowsAppRuntime.Singleton as a dependency package for my msix... Simply adding it in the appx.manifest?

DarranRowe commented 2 years ago

I don't think you can, you only really take a dependency on the main runtime. But the Windows App SDK does have the Microsoft.Windows.ApplicationModel.WindowsAppRuntime namespace which houses the deployment manager classes. So try using DeploymentManager to see if this is what you need.

DexterWoo commented 2 years ago

it feels like a necessary thing to do (adding singleton to the dependency), can that be a possible solution for WindowsAppSDK moving forward? feels bad when you cannot have the correct dependencies installed via store directly.

pmpurifoy commented 2 years ago

The Singleton Package is a package that contains a long running service which supports certain WinAppSDK framework components (currently only Push/AppNotifications). Unpackaged/packaged apps don't need a dependency on the Singleton.

The framework does all the work such as communicating with the long running service which supports App/Push Notifications. The app only needs to have a dependency on the framework but needs help from the DeploymentManager API to get the important packages (Main/Singleton). https://docs.microsoft.com/en-us/windows/apps/windows-app-sdk/deploy-packaged-apps#call-the-deployment-api

pmpurifoy commented 2 years ago

Instead of letting customers get REGDB_E_CLASSNOTREG, we should add a better error code that obviously says "Missing the Singleton Package. Use DeploymentManager APIs to install the Singleton package."

DrusTheAxe commented 2 years ago

FYI this gets better (easier) in 1.2 with the new DeploymentManager auto-initializer - the necessary call to DeploymentManager.Initialize will be linked into your exe to fire when your exe starts, with helpful information (for developers as well as users) if there's a problem. This technique/design is similar to the Bootstrapper API's auto-initializer which make similar pain points largely go away when introduced in 1.1.

1 In theory anything can fail but DepMgr.Init's designed to make that hard/rare to occur.

An early implementation is already in main but always off. I'm in the process of incorporating feedback so available shortly.

gmgallo commented 2 years ago

Hi, jumping in here. I just ran into the same problem today trying to debug a packaged app. This error is predictable and explained in the AppNotificationManager.Register documentation here. The remarks section says this:

"For packaged apps, the COM server is defined in the app manifest. The process calling Register and the process defined in the manifest as the COM server are required to be the same."

I'm working on an App created by Template Studio which includes an optional AppNotificationService. The package.manifest editor is the pleace to make this change as TS obviously doesn't do it. Now I have to figure out how to declare this server in there. Any clues?

DarranRowe commented 2 years ago

The editor doesn't expose this. The instructions that the official Microsoft documentation gives involves editing the XML directly. You can find this documentation here.

cosmin42 commented 2 years ago

I'm getting the same REGDB_E_CLASSNOTREG error just that it is thrown by WinRT.ActivationFactory. I can reproduce this consistently by removing a .dll reference. Is there a way to see the name of the symbol/class that is not found? The way I can fix this at the moment is to guess which dll is missing.

DarthMazut commented 1 year ago

I had the same issue. In my case was enough to install latest SDK from here: https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/downloads After that issue stopped reproducing

stevenbrix commented 9 months ago

i agree with the other sentiments that you should be able to specify the package dependency in the manifest and have it downloaded during install of the msix. having to download on demand means a user can install the app and then have your app be in an invalid state when launched (not to mention having to download something from the internet on first launch?) the windows community toolkit doesn't have this requirement, so why is it needed here?