UnauthorizedAccessException was unhandled by user code when using Geolocator

Your 2020 Plan. Learn 20 minutes a day for 20 days. Online courses from €9.99.

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 🙂

One thought on “UnauthorizedAccessException was unhandled by user code when using Geolocator

  1. Hi,
    I am getting similar error

    ‘Windows.Devices.Geolocation.Geolocator.DefaultGeoposition’ threw an exception of type ‘System.UnauthorizedAccessException’.

    But i dont have WMAppManifest.xml to set Capabilities.

Leave a Reply to anuradha Cancel reply

Your email address will not be published. Required fields are marked *