Value does not fall within the expected range when assigning a lockscreen image

This really has cost me some time and finally I found a solution for it and want to share it with other developers.

Information for all users of my app that encounter this problem: An update is on its way. 🙂

Recently I ported my app “LockScreen calendar” to WP 8.1 to use its new features. WP 8.1 finally allows to get appointments from all calendars, including the calendar category and details for private appointments.

After the release some users reported me a problem that they were not able to assign a lockscreen image. A message with the error text “value does not fall within the expected range” was shown and no lockscreen image was assigned.

First problem: I was not able to reproduce this in the emulator and on one of my physical test devices. 🙁

So what’s the usual thing to try next?
Answer: Ask Google. 🙂

There were many postings about this problem on stackoverflow but in my opinion no useful answer, only links to the lockscreen-example from MS.

Finally I got the vital hint from a user: The app works ok, when installed to the phone but it does not work, when installed on a SD card.

Theoretically there should be no difference since all apps can be moved to an SD card unless the developer does not allow this. To test this, I configured the emulator to install all apps on SD card.

StoreAllOnSD

In the next step I deployed my app from Visual Studio to the emulator. When trying to assign an image to the lockscreen, I was finally able to reproduce the problem.

ValueDoesNotFallInExpectedRange

This is the part of the code that causes the exception message

AssignLockScreenImageException

As you can see, I am calling a method of the LockScreen class here, nothing special.
This call causes the exception that is shown in the app.

So I tried to grant the app access to the “Removable Storage” (in the “Package.appxmanifest” and the “WMAppManifest.xml” file)

AppManifestGrantStorageAccess

…but this did not solve the problem – same error message as shown above.

Finally I ended up, disallowing the app to be installed on SD card.

PreventDeploymentToSDCard

This kind of „solved“ the problem since it does not occur, when the app is installed to the device memory.

I know, this is not the best solution but “LockScreen calendar” does not use much storage memory so at least it’s ok in my opinion.

The other question is: Why IS there a difference, when installing an app to the in device memory vs. installing it on the SD card? Since the user can control, where to install apps or can even move installed apps from the device to an SD card there should be absolutely no difference!

So the “solution” to not allow installing the app on SD card solved the problem for me. If you have the same problem and find a better solution, please let me know. 🙂

2 Gedanken über “Value does not fall within the expected range when assigning a lockscreen image

  1. Krusty

    Hi,
    I’m trying to change lockscreen background, but I have the same problem.
    With 3rd part pic no problem, exception with camera roll picture.

    I have also tried to leave out the possibility to install app to SD card, but error persist and my app become very unstable.
    I have this problem on my Lumia 920 (no SD card), while in the emulator it’s all ok.

    What can I do to solve? 😀

    1. admin Beitrags Autor

      Hi,
      Did you send me an error report to this problem?
      If not, can you please do so?
      You can also contact me via the support email adress that is shown in the app.
      best regarsd,
      Hannes