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 ?
Please make sure you have added a BackgroundTask Declaration in Package.appxmanifest file, checked the System Event and set the Entry Point:

 Elvis Xia - MSFT
 Elvis Xia - MSFTUser contributions licensed under CC BY-SA 3.0