BackgroundTaskBuilder Register() issue


I was developing application with Geofencing, when stuck at issue:

ArgumentException (Value does not fall within the expected range) when I am trying to register background task for geofencing.

Sample from MSDN has the same problem. I will show code from sample for clarity (link to sample: use scenario 5, - instruction how to test).

All what I have done:

  1. Build my app in Visual Studio.
  2. Deploy the app locally first and add the app to the lock screen in Settings.
  3. Close your app that is running locally.
  4. Launch your app in the Visual Studio simulator.
  5. Call RegisterBackgroundTask(..) (simply pressed button register in scenario 5)

There is code from MSDN sample that I have commented for successful app deploying in Simulator - tagged with ////// [my changes] ////////

    async private void RegisterBackgroundTask(object sender, RoutedEventArgs e)

            // Get permission for a background task from the user. If the user has already answered once,
            // this does nothing and the user must manually update their preference via PC Settings.
            //BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();  ////// [my changes] ////////

            // Regardless of the answer, register the background task. If the user later adds this application
            // to the lock screen, the background task will be ready to run.
            // Create a new background task builder
            BackgroundTaskBuilder geofenceTaskBuilder = new BackgroundTaskBuilder();

            geofenceTaskBuilder.Name = SampleBackgroundTaskName;
            geofenceTaskBuilder.TaskEntryPoint = SampleBackgroundTaskEntryPoint;

            // Create a new location trigger
            var trigger = new LocationTrigger(LocationTriggerType.Geofence);

            // Associate the locationi trigger with the background task builder

            // If it is important that there is user presence and/or
            // internet connection when OnCompleted is called
            // the following could be called before calling Register()
            // SystemCondition condition = new SystemCondition(SystemConditionType.UserPresent | SystemConditionType.InternetAvailable);
            // geofenceTaskBuilder.AddCondition(condition);

            // Register the background task
            geofenceTask = geofenceTaskBuilder.Register();

            // Associate an event handler with the new background task
            geofenceTask.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);

            UpdateButtonStates(/*registered:*/ true);

            ////// [my changes] ////////
            //switch (backgroundAccessStatus)
            //    case BackgroundAccessStatus.Unspecified:
            //    case BackgroundAccessStatus.Denied:
            //        rootPage.NotifyUser("This application must be added to the lock screen before the background task will run.", NotifyType.ErrorMessage);
            //        break;

            //    default:
            //        // Ensure we have presented the location consent prompt (by asynchronously getting the current
            //        // position). This must be done here because the background task cannot display UI.
            //        GetGeopositionAsync();
            //        break;
            ////// [my changes] ////////
        catch (Exception ex)
            // HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) == 0x80070032
            const int RequestNotSupportedHResult = unchecked((int)0x80070032);

            if (ex.HResult == RequestNotSupportedHResult)
                rootPage.NotifyUser("Location Simulator not supported.  Could not get permission to add application to the lock screen, this application must be added to the lock screen before the background task will run.", NotifyType.StatusMessage);
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);

            UpdateButtonStates(/*registered:*/ false);

Exception falls on string: geofenceTask = geofenceTaskBuilder.Register();

Can anybody help me?

P.S. Same question thread on msdn -

asked on Stack Overflow Nov 18, 2013 by CatCap • edited Aug 1, 2014 by MAXE

1 Answer


This is a known "bug" see Windows Store 8.1 Location background tasks do not work in simulator. I have yet to get an answer other than

Your issue has been routed to the appropriate VS development team for investigation

Please upvote it!

answered on Stack Overflow Nov 18, 2013 by Shawn Kendrot

User contributions licensed under CC BY-SA 3.0