0

I have a Xamarin.Forms application, which uses Xamarin.Essentials and Plugin.Permissions plugin.

permissionStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

In UWP, It throws an Exception

"Server execution failed".

Any ideas what can cause it, and how this can be solved?

David Shochet
  • 5,035
  • 11
  • 57
  • 105
  • ,If I check Location in package.appxmanifest, I use `Geolocation.GetLocationAsync()` I don't find any error, and I can get Latitude and Longitude. So can you provide one demo that can reproduce this issue here? – Cherry Bu - MSFT Aug 22 '19 at 06:35
  • @Cherry Bu Hmm, things changed, and I updated my original question. – David Shochet Aug 26 '19 at 18:22
  • ,According to your code, you want to get location permission for your project? if yes, please take a look my reply. – Cherry Bu - MSFT Aug 27 '19 at 05:54

1 Answers1

0

According to your code, I guess that you want to request and check location permission, if yes, you can take a look the following code to request location permission.

 try
        {
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);
            if (status != PermissionStatus.Granted)
            {
                if(await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                {
                    await DisplayAlert("Need location", "Gunna need that location", "OK");
                }

                var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);
                status = results[Permission.Location];
            }

            if (status == PermissionStatus.Granted)
            {
                var results = await CrossGeolocator.Current.GetPositionAsync(TimeSpan.FromSeconds(10));
                LabelGeolocation.Text = "Lat: " + results.Latitude + " Long: " + results.Longitude;
            }
            else if(status != PermissionStatus.Unknown)
            {
                await DisplayAlert("Location Denied", "Can not continue, try again.", "OK");
            }
        }
        catch (Exception ex)
        {

            LabelGeolocation.Text = "Error: " + ex;
        }

Please check Location in package.appxmanifest before.

Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16
  • But I have the problem with the very first statement. You can see that your code does not differ from mine on that line... And I do have the Location checked... – David Shochet Aug 27 '19 at 13:25
  • @David, I don't think so, because the parameter type in CrossPermissions.Current.CheckPermissionStatusAsync() method is Permission, so if you want to get Location permission, it should be Permission.Location. If you want to get location permission, I suggest you can try my code firstly. – Cherry Bu - MSFT Aug 28 '19 at 01:50
  • The "permission" that I pass is actually set to Permission.Location. This part of code is just not included in my question. – David Shochet Aug 28 '19 at 12:18
  • @David, now, I am confused about your problem, do you try my code? – Cherry Bu - MSFT Aug 29 '19 at 07:51
  • The first line of your code is the same that I have. And that line throws an exception. There is no point to go further, as the execution never passes the FIRST line (CrossPermissions.Current.CheckPermissionStatusAsync). – David Shochet Aug 29 '19 at 13:03