Wednesday, May 14, 2014

System.UnauthorizedAccessException: Access is denied

So you are coding up your next big app and cruising along, but suddenly you face an error like the following:

{System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

Fear not, my friend, this is a simple case of Missing Capabilities.

For example, if you are trying to fetch the geolocation of a user, that means you are missing the ID_CAP_LOCATION capability. If you are coding a Windows Phone app, you need to open WMAppManifest.xml file in the designer in Visual Studio and then go to the Capabilities tab and select the checkbox next to ID_CAP_LOCATION.

Similarly, if you try to access other features and the corresponding capabilities are are not enabled you might see this error message as well.

Remember, there are 3 things that matter when accessing any device based features in your Windows apps: Capabilities, Capabilities, Capabilities.

Till next time,
Paras Wadehra
Microsoft MVP and Ambassador
Twitter: @ParasWadehra
FB.com/WindowsPhoneDeveloper
My WP Apps

No comments: