Bug 11950 - ApplicationInfo.SharedLibraryFiles contains invalid enumerable
Summary: ApplicationInfo.SharedLibraryFiles contains invalid enumerable
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.6.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2013-04-24 17:22 UTC by info
Modified: 2013-05-23 10:18 UTC (History)
3 users (show)

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

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 info 2013-04-24 17:22:05 UTC
ApplicationInfo.SharedLibraryFiles contains a non-null value that appears to implement IList<string>, but will throw an exception whenever it is enumerated.

The following code snippet throws a NullReferenceException at the last line:

var enumerator = ApplicationInfo.SharedLibraryFiles.GetEnumerator();
if (enumerator == null) return;
enumerator.MoveNext ();

The 'enumerator' variable appears to reference a 'Android.Runtime.JavaArray`1' type, and not an actual enumerator, although a check against IEnumerator will yield true. Very strange.

Xamarin.Studio also suffers from this issue internally - when inspecting an ApplicationInfo object, the inspector will show an 'Object not initialized' message for SharedLibraryFiles instead of the error.
Comment 1 Peter Collins 2013-05-14 18:44:19 UTC
I am able to reproduce this NRE with the above code snippet on our current stable build of X.A. (4.6.4 - 03814ac5) on both Windows and OSX.
Comment 2 Jonathan Pryor 2013-05-14 20:18:43 UTC
This is a binding bug: we're not properly null-checking the return value of JNIEnv.GetObjectField(), so in this case we're effectively doing:

    public IList<string> SharedLibraryFiles {
        get {
            return new JavaArray<string> (IntPtr.Zero, JniHandleOwnership.TransferLocalRef);


WORKAROUND: Manually perform the null check! (bleh!)

    var libs  = ApplicationInfo.SharedLibraryFiles;
    var array = libs as JavaArray<string>;
    if (array != null && array.Handle == IntPtr.Zero)
Comment 3 Jonathan Pryor 2013-05-23 09:07:57 UTC
Fixed in master/59209e6e.
Comment 4 info 2013-05-23 10:18:12 UTC