There is a random bug as mentioned below which says something wrong while setting the SystemTray
visibility. I have set the SystemTray
visibility to false in xaml. It randomly crashes the app sometimes and not always. The exception thrown is System.ArgumentException
Value does not fall within the expected range.
The stacktrace is as below
Microsoft.Phone.Shell.Interop.NativeSystemTrayMethods.SetSysTrayVisible(IntPtr pSysTray, Boolean fVisible)
Microsoft.Phone.Shell.Interop.NativeSystemTrayInteropWrapper.SetSystemTrayVisible(Boolean isVisible)
Microsoft.Phone.Controls.PhoneApplicationPage.set_SystemTrayIsVisible(Boolean value)
Microsoft.Phone.Controls.PhoneApplicationPage..ctor()
What can be the probable reason for it? Any workarounds? Any leads are appreciated.
This is not a solution in any way.
We are seeing the same error mostly (90%) on WP8.0 devices and there is a very very small percentage of WP8.1 devices. Other error reports do not contain version of the OS for some reason.
Here is what we found out with advanced technical support from Microsoft.
This is a known problem that was fixed for WP8.1.
I looked at the SetSystemTrayVisible bug that stack trace suggests and confirmed should be fixed in WP8.1.
I’m not sure why you’re seeing some instances on 8.10.14234, but there may be a second, rarer, issue in that area
Unfortunately, there isn’t anything you can do in your code to prevent this on WP8.0. The problem occurs in the root page initialization where it’s setting the default state of the system tray. There’s an incorrect guard check in native interop, so if a handle gets initialized to a bad value the exception is raised. The guard was fixed for WP8.1
You should be able to detect the error ... expect it to trigger the Application_UnhandledException handler from which you can display a message box.
So the best way to handle that exception is to just catch it (detect) and then suggest user to upgrade the OS to WP8.1. I am not sure how feasible is that cause we were unable to reproduce this error on our devices or emulators.
Hope this helps!