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

In this post, you’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...