Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio error: "Cannot activate background task. Background Task activation failed."

When I try to launch a particular background task using Visual Studio, I currently receive the following error:

Cannot activate background task. Background Task activation failed

I tried pressing the Help button, which took me to How to trigger suspend, resume, and background events in Windows Store apps. The page said to look at a certain section in Event Viewer that didn't contain any entries.

The corresponding Windows Store application is both requesting background task permission and registering the task. The application is enabled for the lock screen. The application's project is referencing the background task project, and its manifest is specifying the correct fully-qualified class name of the background task. The correct type of background task has been specified in the manifest.

like image 712
Sam Avatar asked Nov 03 '22 03:11

Sam


2 Answers

I was able to resolve this by changing the task registration/location code to call RequestAccessAsync before registering the background task. (Previously, it had registered the background task before asking for access.)

For some reason, this caused the application to request access again. After running the application and granting it permission, I reverted the code back to the previous state.

Now it works correctly again even though the code is the same as it was originally.

like image 119
Sam Avatar answered Dec 28 '22 11:12

Sam


For me, I had a problem where I had updated TaskEntryPoint in my manifest but forgot to update it in my code... Frustrating to have to maintain it both places!

It got out of sync via the process of refactoring some classes into a new library, so don't forget to update after the fact if you do that!

You may be able to use reflection to help with this e.g. typeof(LocationTask).FullName

like image 39
jocull Avatar answered Dec 28 '22 10:12

jocull