The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
[WPSL]Class not registered (Exception from HRESULT: 0x80040154) when BackgroundExecutionManager.RequestAccessAsync in Windows Phone 8.1 RRS feed

  • Question

  • I am trying to implement Background Tasks in my project. So I added a Windows Runtime Component Project and given reference to it from my main Windows Phone 8.1 silverlight project. But When I calling the below function I am getting an exception

    "A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll. Additional information: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"

            // Applications must have lock screen privileges in order to receive raw notifications
            BackgroundAccessStatus backgroundStatus = await BackgroundExecutionManager.RequestAccessAsync();
    
            // Make sure the user allowed privileges
            if (backgroundStatus != BackgroundAccessStatus.Denied && backgroundStatus != BackgroundAccessStatus.Unspecified)
            {
                OpenChannelAndRegisterTask();
            }
            else
            {
                // This event comes back in a background thread, so we need to move to the UI thread to access any UI elements
                Dispatcher.BeginInvoke(() =>
                {
                    Debug.WriteLine("Lock screen access is denied");
                });
            }

    Why this happens? Later I create a sample Windows phone project and the above code is working fine. But it is never easy to copy entire codes to a new project. What will be the reason for this strange issue? 

    Please help me to resolve this issue if you have any clue about it.


    anoop m

    Tuesday, September 15, 2015 10:50 AM

All replies

  • I wasted 5 days trying to figure this out a few months back with a winRT component class: it lacked a default constructor (with no params). Once I added one empty ctor with no params, it worked fine.

    Tuesday, September 15, 2015 12:23 PM
  • Hi mcosmin,

    Where you put the constructor? In the BackgroundTask class ? Can you please confirm ?


    anoop m

    Wednesday, September 16, 2015 6:57 AM
  • Ye, you can try that. Just put an empty constructor there with no params. Either that or you are not exposing your class properly. Please paste the code here.

    Wednesday, September 16, 2015 7:17 AM
  • Hi please find the code below

    namespace BgTask
    {

      public sealed class NotificationBackgroundTask : IBackgroundTask
        {

            public void Run(IBackgroundTaskInstance taskInstance)
            {

                     ...

             }

       }

    }


    anoop m



    • Edited by asitis dobt Wednesday, September 16, 2015 7:27 AM
    Wednesday, September 16, 2015 7:21 AM
  • Does the namespace match the component namespace?

    Did you add reference to your component from the main project?

    • Edited by mcosmin Wednesday, September 16, 2015 7:26 AM
    Wednesday, September 16, 2015 7:25 AM
  • Does the namespace match the component namespace?
    Yes. Edited the class with namespace.

    anoop m

    Wednesday, September 16, 2015 7:27 AM
  • You changed the namespace in which the class resides?
    Wednesday, September 16, 2015 7:31 AM
  • You changed the namespace in which the class resides?
    I have added Windows Runtime project 'BgTask' and added reference it to the main project. In the packagemanifest I added pushnotification entry point as 'BgTask.NotificationBackgroundTask'

    anoop m

    Wednesday, September 16, 2015 7:36 AM
  • ... did you change the ORIGINAL namespace in which your background task resides or not?

    The namespace must match the default namespace that is stored in project settings. Otherwise it will not register properly.

    Wednesday, September 16, 2015 7:48 AM
  • ... did you change the ORIGINAL namespace in which your background task resides or not?

    The namespace must match the default namespace that is stored in project settings. Otherwise it will not register properly.

    I didn't change any namespace. But I renamed 'class1'.cs' file to 'NotificationBackgroundTask.cs'

    anoop m

    Wednesday, September 16, 2015 9:38 AM
  • That alone shouldn't cause any issues.

    Make sure there aren't any inconsistencies between project settings and code, make sure the reference is set to your background task, make sure that the "namespace.class" string is the same in appxmanifest and when you register the class and the names of the namespace and class are the same as the names defined in code.

    This error is caused by an inconsistency. Unless we have the entire code base, we can't do much on the forum.

    Wednesday, September 16, 2015 9:48 AM
  • Perhaps...You have to create a new project, there is no tool to verify if something has been broken...

    Or contact paid support, they may check the project for you


    Best Regards,
    Please remember to mark the replies as answers if they help

    Thursday, September 17, 2015 10:52 AM
  • That alone shouldn't cause any issues.

    Make sure there aren't any inconsistencies between project settings and code, make sure the reference is set to your background task, make sure that the "namespace.class" string is the same in appxmanifest and when you register the class and the names of the namespace and class are the same as the names defined in code.

    This error is caused by an inconsistency. Unless we have the entire code base, we can't do much on the forum.

    Hey ,

    I created a new project to implement background task and it has no issues and background task Run method firing when any raw notification received. But at the same moment background task agent exited and not entering inside the Run method. Please find below error.

    'BACKGROUNDTASKHOST.EXE' (CoreCLR: DefaultDomain): Loaded 'C:\windows\system32\mscorlib.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\Data\Programs\{A3C005D7-1A56-4070-9B81-2AAEFD6C5B8D}\Install\ChillrBgTask.winmd'. Symbols loaded.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.RUNTIME.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\WinMetadata\Windows.winmd'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.THREADING.TASKS.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.DIAGNOSTICS.DEBUG.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\System.Runtime.WindowsRuntime.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.The program '[4484] BACKGROUNDTASKHOST.EXE' has exited with code 1 (0x1).
    Why is it? Nothing inside the Run method working. Or background task ms has created is not mean't for Silverlight ? Please confirm


    anoop m

    Thursday, September 17, 2015 2:02 PM
  • Perhaps...You have to create a new project, there is no tool to verify if something has been broken...

    Or contact paid support, they may check the project for you


    Best Regards,
    Please remember to mark the replies as answers if they help

    Hey ,

    I created a new project to implement background task and it has no issues and background task Run method firing when any raw notification received. But at the same moment background task agent exited and not entering inside the Run method. Please find below error.

    'BACKGROUNDTASKHOST.EXE' (CoreCLR: DefaultDomain): Loaded 'C:\windows\system32\mscorlib.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\Data\Programs\{A3C005D7-1A56-4070-9B81-2AAEFD6C5B8D}\Install\ChillrBgTask.winmd'. Symbols loaded.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.RUNTIME.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\WinMetadata\Windows.winmd'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.THREADING.TASKS.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.DIAGNOSTICS.DEBUG.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.'BACKGROUNDTASKHOST.EXE' (CoreCLR: .): Loaded 'C:\windows\system32\System.Runtime.WindowsRuntime.NI.DLL'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.The program '[4484] BACKGROUNDTASKHOST.EXE' has exited with code 1 (0x1).
    Why is it? Nothing inside the Run method working. Or background task ms has created is not mean't for Silverlight ? Please confirm



    anoop m

    Thursday, September 17, 2015 2:04 PM