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 🙂

    1 Comment

  1. anuradha
    May 14, 2018
    Reply

    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

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

You May Also Like

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...