DEP0700: Registration of the app failed with PushNotification

Enrico Rossini 201 Reputation points
2024-02-26T16:30:34.42+00:00

In my .NET 8 MAUI application for Windows, I would like to receive push notifications even when the app is closed. For that, I tried to add a background task using this code:

private async void RegisterBackgroundTask()
{
    var builder = new BackgroundTaskBuilder();
    builder. Name = "PushNotificationBackgroundTask";
    builder.SetTrigger(new PushNotificationTrigger());
    builder. Register();
}

Then, I registered the function in the OnLaunched function:

protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
    base.OnLaunched(args);
    RegisterBackgroundTask();
}

When I run the application, I get this error

System.ArgumentException: 'Value does not fall within the expected range.'

enter image description here

I tried to set some Capabilities like that but not luck

enter image description here

So, I tried to move the background service in a different class

public sealed class PushBackgroundTask : IBackgroundTask
{
    private const string TASK_NAME = "notif_push_task";

    public static void Register()
    {
        BackgroundTaskBuilder builder = new BackgroundTaskBuilder();

        builder.TaskEntryPoint = typeof(PushBackgroundTask).FullName;
        builder.Name = TASK_NAME;
        builder.SetTrigger(new PushNotificationTrigger());
        BackgroundTaskRegistration task = builder.Register();
    }
}

and then add in the Declarations a Background Tasks like that

enter image description here

but in this case, I get another error

DEP0700: Registration of the app failed. [0x80080204] error 0x80080204: App manifest validation error: Line 49, Column 12, Reason: If it is not an audio background task, it is not allowed to have EntryPoint="LanguageInUse.Platforms.Windows.PushBackgroundTask" without ActivatableClassId in windows.activatableClass.inProcessServer.

As a side note, the implementation of Push notifications in MAUI and Azure Notification Hub is a nightmare.

How can I fix this code? What Capabilities, Declarations or permissions do I have to add?

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2024-02-27T05:23:12.7866667+00:00

    Hello,

    This error is expected because according to the official documentation, before you can use BackgroundTask, you need to register it through Extensions.

    Please refer to Declare in the app manifest that your app uses background tasks for more detailed information.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.