Bug 34732 - Runtime crash when enumerating Permission[] grantResults value from OnRequestPermissionsResult
Summary: Runtime crash when enumerating Permission[] grantResults value from OnRequest...
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 5.2
Hardware: Macintosh Mac OS
: High normal
Target Milestone: master
Assignee: Rodrigo Kumpera
: 34949 ()
Depends on:
Reported: 2015-10-09 15:02 UTC by Peter Collins
Modified: 2017-08-15 22:13 UTC (History)
10 users (show)

Is this bug a regression?: ---
Last known good build:

repro case (28.20 KB, application/zip)
2015-10-09 15:45 UTC, Peter Collins

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Peter Collins 2015-10-09 15:02:20 UTC
If I try to use Linq's Any () function to determine if my permission array is empty, my app crashes with the following:

> System.Int32[] doesn't implement interface System.Collections.Generic.IEnumerable<Android.Content.PM.Permission>

##### Full Logcat output #####

##### Steps to reproduce #####
1. Download the attached sample and tap the button.

##### Workaround #####
Use `grantResults.Length > 0`  instead of `grantResults.Any ()`

##### Environment #####
Operating System: Mac OS X 10.10.5
Repo Name: monodroid.git
Branch Name: monodroid-5.1-series-android-mnc
Build Revision: 53fce3730830417896a42f365a5ba35f1ee58d9d
Comment 1 Jonathan Pryor 2015-10-09 15:16:20 UTC
Is there source code or a sample here to look at?
Comment 2 Peter Collins 2015-10-09 15:45:05 UTC
Created attachment 13263 [details]
repro case

Attachment fail...
Comment 6 Jérémie Laval 2015-10-16 16:39:16 UTC
I still personally think that it's a valid technique to use for an array (we should have someone from runtime at least shim in on that I think).

My request for inclusion in C6 is based on the bug affecting an essential feature of Marshmallow (basically, the #1 reason why people would be switching to Marshmallow). It's definitely not a regression I agree.
Comment 8 Peter Collins 2016-02-22 17:10:01 UTC
*** Bug 34949 has been marked as a duplicate of this bug. ***
Comment 9 Niels 2016-06-13 14:59:25 UTC
I ran into this same bug today when trying to do this: grantResults.All(x => x == Permission.Granted)
Comment 10 Rodrigo Kumpera 2016-11-14 22:13:21 UTC
Working on it.
Comment 11 Kornelis 2017-03-02 13:32:36 UTC
Ran into this issue this week. Apparently it is still not solved.

Workaround if you prefer to use Linq is to do it like this:

int[] grantResultsInt = grantResults.Select(gr => (int) gr).ToArray();
if (grantResultsInt.All(gr => gr == (int)Permission.Granted) &&
     Enum.IsDefined(typeof (Mobile.App.Components.Enums.Permission), permission))
Comment 12 Rodrigo Kumpera 2017-03-02 19:26:25 UTC
This was fixed on mono/master.

The forecast is that it will ship on 15.2 (Late Spring)
Comment 13 Rodrigo Kumpera 2017-08-15 22:13:37 UTC
And it shipped.