Subscribe to our YouTube Channel for more Videos

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 🙂

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.