Essentials: [Bug] UWP - Permissions.CheckStatusAsync

Created on 27 Feb 2020  路  5Comments  路  Source: xamarin/Essentials

Description

I trying to check permission:
var camera = await Permissions.CheckStatusAsync<Permissions.Camera>();
and get exeption - "Object reference not set to an instance of an object."

   at Xamarin.Essentials.Permissions.BasePlatformPermission.EnsureDeclared()
   at Xamarin.Essentials.Permissions.BasePlatformPermission.CheckStatusAsync()
   at Xamarin.Essentials.Permissions.CheckStatusAsync[TPermission]()

I was trying other permissions and results is the same

Xamarin.Essentials 1.4.0Xamarin.Essentials 1.5.0

bug

Most helpful comment

It will just return Granted.

So in your code you can just do:


if(DeviceInfo.Platform == DevicePlatform.UWP)
///granted
else
//check

Then when you upgrade to 1.5.1 you can remove the check, but it actually wouldn't matter too much.

All 5 comments

Did you set the Manifest permission?

yes, I used Plugin.Permission, and after I updated Xamarin.Essentials I just refactor my code to remove Plugin.Permission and starting use Xamarin.Essentials
@jamesmontemagno

Ah, yes so if it is a permission that isn't supported it is throwing this exception. It should by default say granted. I will have a fix for this in 1.5.1, but for now I would put a check for UWP and only use it for permissions supported.

https://docs.microsoft.com/en-us/xamarin/essentials/permissions#available-permissions

Thanks, I will wait 1.5.1 :)

It will just return Granted.

So in your code you can just do:


if(DeviceInfo.Platform == DevicePlatform.UWP)
///granted
else
//check

Then when you upgrade to 1.5.1 you can remove the check, but it actually wouldn't matter too much.

Was this page helpful?
0 / 5 - 0 ratings