Search code examples
c#windowsuwpwns

Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)) in UWP Background process registration


While trying to register a background task in windows uwp, I am facing the following error at task2.Register();

Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

Here is my code:

private async void RegisterBackgroundTask_Click(object sender, RoutedEventArgs e)
    {
        var taskReg = false;

        foreach( var task1 in BackgroundTaskRegistration.AllTasks)
        {
            if(task1.Value.Name == SAMPLE_TASK_NAME)
            {
                taskReg = true;
                break;
            }

        }

        if(!taskReg)
        {
            var access = await BackgroundExecutionManager.RequestAccessAsync();
            var task2 = new BackgroundTaskBuilder
            {
                Name = SAMPLE_TASK_NAME,
                CancelOnConditionLoss = false,
                TaskEntryPoint = SAMPLE_TASK_ENTRY_POINT,
            };

            var trigger = new ToastNotificationActionTrigger();
            task2.SetTrigger(trigger);

            //var condition = new SystemCondition(SystemConditionType.InternetAvailable);
            task2.Register();

Any solution for such an error ?


Solution

  • Please make sure you have added a BackgroundTask Declaration in Package.appxmanifest file, checked the System Event and set the Entry Point: enter image description here