UnauthorizedAccessException was unhandled by user code when using Geolocator

When using the Geolocator class or when planning to implement the location API in your Windows Phone App, it is necessary that the necessary capabilities are included in your Windows Phone project.

Below is an error that is displayed when trying to use the Geolocator class.

An exception of type ‘System.UnauthorizedAccessException’ occurred in mscorlib.ni.dll but was not handled in user code

UnauthorizedAccessException was unhandled by user code when using Geolocator

How to handle the “UnauthorizedAccessException was unhandled by user code” error when using Geolocator?

To solve this error, simply enable the ID_CAP_LOCATION capability in your App. To set this capability, double click on the WMAppManifest.xml in the solution explorer. This will display the GUI editor where you can modify the settings of your App.

Navigate to the Capabilities tab and simply check/select the option “ID_CAP_LOCATION” and save the project.

How to handle the "UnauthorizedAccessException was unhandled by user code" error when using Geolocator?

Build and Run your project. You should app running without any error when using Geolocator class now 🙂

Leave a Reply