Adding UWP Background task causes AppManifest errors
Asked Answered
G

7

7

I've been trying to add an out of process background task to my project to update my App's live tile. The task needs to make a database call to get some data, then process that data to send out a few tile notifications.

I've managed to get it to work in one project that I created specifically for prototyping the background task functionality. However, when I tried to add a background task to my main project it gives me the following error:

Validation error. error 80080204: App manifest validation error: Line 33, Column 12, Reason: If it is not an audio background task, it is not allowed to have EntryPoint="BackgroundTasks.LiveTileTask" without ActivatableClassId in windows.activatableClass.inProcessServer. 

I have searched for this error and found some post which said I should add the audio task type and the error would go away, but then I get a different error. I'm not even trying to play audio in the background, so it's beyond me why UWP thinks I am.

My project setup looks like this:

  • 1 UWP project targeting fall creator's update as min/target version.
  • 1 net standard 2.0 project for the database (with EFcore)

I've tried following the guidelines published by Microsoft, and add a WinRT project solely for the background task, but that gives compatibility issues all over the place with my .net standard 2.0 project and the UWP project. I'm not a very experienced UWP developer, so I'm wondering if anyone sees something that I'm missing.

What would be the best approach to getting my background task working? Is an in-process background task sufficient for updating the live tile from the background, even if the app is not opened?

EDIT: I'm using the latest version of VS 2017 (15.7.1)

Garrot answered 18/5, 2018 at 7:7 Comment(2)
If @Raymond Osterbrink's suggestion could not resolve your issue, please provide a minimal reproducible example, I would help you test and diagnose it on my side. You could upload it and post link here.Martymartyn
@XavierXie-MSFT This problem exists when I followed this tutorial: learn.microsoft.com/en-us/windows/uwp/launch-resume/…Arthurarthurian
L
5

I hit the same issue. Unfortunately adding audio is not a solution as this will be a requirement for the windows store, not a good idea. Setting minimum target version gives you very limited Windows Store functionality and less UWP features.

Get started by using this link and follow it very carefully:

https://learn.microsoft.com/en-us/windows/uwp/launch-resume/create-and-register-a-background-task

To summarise:

  • Ensure you have a good copy of your project, my manifiest file became corrupted during experimentation and I needed the Package.appxmanifest backup copy.
  • Delete all references and code relating to anything to do with background tasks from your project.
  • In your solution create a new Windows Universal / Windows Runtime Component project.
  • Name the project BackgroundTasks (as an example)
  • Right click references and Manage Nuget Packages
  • Select the installed tab and Microsoft.NETCore.UniversalWindowsPlatform
  • Change the version from 6.1.4 to 6.0.8 (6.1.4 seems to be a preview version which causes extra unwanted references to be added everytime VS is loaded).
  • Change Class1.cs name to MyBackgroundTask.cs
  • Select the BackgroundTasks project Target / Min version to Fall Creators Update
  • Right click your solution / Project Dependancies. Select BackgroundTasks and check the build order is correct, mine is set for BackgroundTasks to build before the main project.
  • Refer to the sample code at UWP Samples to create the sample background task.
  • Change the Package.appxmanifest file as described on the above link.
  • Build the solution and you should be in business.

Personally I recommend to use an out-of-process background task to eliminate any possibly that if the background task crashes it does not affect the app from running, also much more flexible.

As a tip your BackgroundTaskBuilder will reference as strings:

 builder.Name = "MyBackgroundTask";
 builder.TaskEntryPoint = "BackgroundTasks.MyBackgroundTask";

I find making background tasks in UWP quite tedious, but once done well worth the effort.

Leafy answered 27/5, 2018 at 9:32 Comment(1)
Thanks for the summarized explanation, but I'm stuck with a bizarre situation. 1.My existing application(project in this context) get streamsocket data, update DB and do lot of other stuff. 2.When in background I have implemented a BackgroundTasks project as above. 3.Now the data is received in the BackgroundTasks project but I still need to update the DB, send alert mail and do whole lot of other tasks still handled in original project. There could be design flow in this, but this requirement came from client once the app is deployed. It there a proper way to handle this?Liquidator
D
5

I only had to add a reference to the BackgroundTask project in the main project.

Dishman answered 4/10, 2019 at 12:28 Comment(0)
G
0

Thank you for the MSDN-Link since I stumbled uppon exact the same problem.

Following all the discriptions from the link helped me starting my app. I followed this stepps:

  • adding Type:audio to my appxmanifest manualy
  • Changing the BackgroundTask Project To a Windows Runtime Class Library
  • Setting the Minimum Target Version to 15063

Especialy the last step seems mandatory, hope this does not conflict with your desired needs.

Gallion answered 18/5, 2018 at 11:44 Comment(0)
E
0

I pulled out my hair on this one too. I finally solved it by just setting the Target and Min version respectively to Fall Creators Update (build 16299) and (most crucial) the November Update (build 10586).

Side note 1 RedStone 4 release (version 1803; build 17133) is now avail at the time of writing my answer but I limited the Target version to Fall Creators (and even had to restore my development PC back to 1709; build 16299) due to too many issues with the development with my project.

Side note 2 Setting the Min version further back gave me missing functionality (like a missing System.Diagnostics.Trace symbol).

Eat answered 30/5, 2018 at 6:36 Comment(0)
A
0

Setting the Minimum Target Version to 15063 in my projects fixed this error for me.

Acoustics answered 3/2, 2020 at 15:23 Comment(0)
R
0

I had the same issue and found a solution. You need to specify the full namespace for the EntryPoint:

     <Extensions>
        <Extension Category="windows.backgroundTasks" EntryPoint="FullNameSpace.Background.ToastNotificationBackgroundTask">
          <BackgroundTasks>
            <Task Type="systemEvent"/>
          </BackgroundTasks>
        </Extension>
      </Extensions>
    </Application>
  </Applications>
Rabblerousing answered 4/3, 2021 at 21:25 Comment(0)
O
0

In my case, I had the same error when I modified the Package.appxmanifest file by editing directly the XML with the background task <Extension> element

Then, it is solved after deleting the modification and adding the Extension using the package manifest designer of Package.appxmanifest. Steps are defined in this link: https://learn.microsoft.com/en-us/windows/uwp/launch-resume/create-and-register-a-background-task#declare-in-the-app-manifest-that-your-app-uses-background-tasks

Ordure answered 29/6, 2022 at 11:50 Comment(1)
This runs well, indeed. However I get problems handling ToastButton events. See here. Obviously there is no way to handle events in Windows Universal / Windows Runtime ComponentsPromiscuity

© 2022 - 2024 — McMap. All rights reserved.