Bug 40554 - Application crash when return System.IO.Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal), ANDROID_DB_FILE); on Android API 23
Summary: Application crash when return System.IO.Path.Combine (System.Environment.GetF...
Status: RESOLVED NORESPONSE
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2016-04-20 12:38 UTC by Jakub Holovsky
Modified: 2017-08-21 21:38 UTC (History)
4 users (show)

Tags:
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:
Status:
RESOLVED NORESPONSE

Description Jakub Holovsky 2016-04-20 12:38:47 UTC
Our application crashes on Xamarin Android Player (also crashes on Genymotion) running Android API 23 when we try to get our database path. Our class looks like this:

public class DBUtils
    {
        /// <summary>
        /// The file we are using to store our Android database
        /// </summary>
        private static readonly string ANDROID_DB_FILE = "PsonarAndroid.db3";

        /// <summary>
        /// Gets the Psonar Android database location.
        /// </summary>
        /// <value>
        /// The database location string, converted for the platform.
        /// </value>
        public static string DatabaseLocation
        {
            get
            {
                // Set the Mono for Android SQLite db location
                return System.IO.Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal), ANDROID_DB_FILE);
            }
        }
    }

This code works perfectly fine on lower versions of Android. I am not able to get any exception other than the one that our application is throwing which is misleading however here it is:

{System.NullReferenceException: Object reference not set to an instance of an object
  at Psonar.Apps.Droid.PayPerPlay.BaseActivity.get_PsonarUserManager () [0x00000] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\UI\BaseActivity.cs:33 
  at Psonar.Apps.Droid.PayPerPlay.LoginActivity.HandleLogin (System.Object sender, System.EventArgs e) [0x000cb] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\UI\LoginActivity.cs:101 
  at Android.Views.View+IOnClickListenerImplementor.OnClick (Android.Views.View v) [0x0000d] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1938 
  at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v) [0x00011] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1903 
at (wrapper dynamic-method) object:5ffa2795-4127-4d68-aefb-16bb548218ac (intptr,intptr,intptr)}

If I replace:

return System.IO.Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal), ANDROID_DB_FILE);

with:

return Application.Context.GetDatabasePath(ANDROID_DB_FILE).AbsolutePath;

then the application works fine on API 23. Even though that this fixes it it still seems like a bug in Xamarin.

My configuration:

Microsoft Visual Studio Community 2015
Version 14.0.24720.00 Update 1
Microsoft .NET Framework
Version 4.6.01038

Installed Version: Community

Visual Basic 2015   00322-20000-00000-AA253
Microsoft Visual Basic 2015

Visual C# 2015   00322-20000-00000-AA253
Microsoft Visual C# 2015

Visual C++ 2015   00322-20000-00000-AA253
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU   00322-20000-00000-AA253
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   4.3.60226.3
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015 (RC1 Update 1)   14.1.20203.0
ASP.NET and Web Tools 2015 (RC1 Update 1)

ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.40204.0
For additional information, visit http://www.asp.net/

Azure App Service Tools v2.8.2   14.0.20201.0
Azure App Service Tools v2.8.2

Common Azure Tools   1.7
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

DataFactoryProject   1.0
Microsoft Data Factory Package

GitHub.VisualStudio   1.0
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

JetBrains ReSharper Ultimate 10.0.2   Build 104.0.20151218.120627
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2016 JetBrains, Inc.

Microsoft Azure Data Factory Node Node   1.0
Azure Data Factory extension for Visual Studio Server Explorer.

Microsoft Azure HDInsight HQL Service   2.0.2900.0
Language service for Hive query

Microsoft Azure HDInsight Tools for Visual Studio   2.0.2900.0
An integrated development environment for HDInsight application development.

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

Microsoft Azure Tools   2.8
Microsoft Azure Tools for Microsoft Visual Studio 2015 - v2.8.40211.2

NuGet Package Manager   3.4.2
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.50730.0
Microsoft SQL Server Data Tools

TypeScript   1.7.6.0
TypeScript for Microsoft Visual Studio

Visual Studio Tools for Universal Windows Apps   14.0.24720.00
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Xamarin   3.11.1594.0 (a06d6d5)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   5.1.7.12 (53fce3730830417896a42f365a5ba35f1ee58d9d)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.Forms Intellisense   1.0
Provides intellisense for Xamarin.Forms in the XML editor.

Xamarin.iOS   9.1.0.0 (023e4c64eb456050e86dac6953aa0a576a70ac91)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified

Xamarin.TestCloud.Integration   1.0
Early preview of Xamarin Test Cloud integration
Comment 1 Marek Safar 2016-04-20 15:28:38 UTC
This is quite confusing. Your code in get_PsonarUserManager throws NRE but you didn't show us what's there but you included DatabaseLocation code instead.

Does DatabaseLocation return null or how is it related to the NRE?
Comment 2 Jakub Holovsky 2016-04-20 19:34:49 UTC
As I said above the Exception looks very unrelated however it is thrown when the getter of the property crashes the app.

Namely, this line crashes it:

return System.IO.Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal), ANDROID_DB_FILE);

As soon as the System.IO.Path.Combine is hit it crashes the app with no other information. It is very confusing issue however I was able to isolate it to this line which happens on API 23 only (with the above configuration I have).

The NRE is related to the fact in which we are accessing the DatabaseLocation property which is in here:

public UserManager @UserManager
        {
            get 
            {
                lock (this)
                {
                    return this.m_userManager ??
                           (this.m_userManager = new UserManager(Session.Instance.ApiClient,
                               new Database<User>(DBUtils.DatabaseLocation)));
                }
            }
        }

As the DatabaseLocation fails it fails to create a user manager that's why there is the NRE.

So my suspect is that there is something wrong with System.IO.Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal)

if this is in the wrong category then I apologize for the confusion.
Comment 3 Marek Safar 2016-04-21 07:54:47 UTC
.
Comment 4 Marek Safar 2016-04-21 07:55:31 UTC
If you think it's coming from System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) could you get NRE stack trace from it?
Comment 5 Jonathan Pryor 2016-04-23 16:12:22 UTC
`System.Environment.SpecialFolder.Personal` is $HOME, which on Android is mapped to the app's `files` directory, e.g. /data/data/@PACKAGE_NAME@/files.

GetFolderPath(SpecialFolder.Personal) should *never* return a null value or the empty string. (This isn't asserted in code, but I can't imagine how it could possibly happen, either.)

Circling back to Comment #2:

> As the DatabaseLocation fails it fails to create a user manager that's why there is the NRE.

I don't believe that is the observed behavior. As per the stack trace in Comment #0, the NullReferenceException is coming from get_PsonarUserManager(). (Is that a typo? Comment #2 suggests this should be get_UserManager().) Meaning whatever null reference is being dereferenced within get_PsonarUserManager() needs to be done *within* get_PsonarUserManager(), not get_PsonarUserManager() and any method or constructor it invokes.


> /*  1 */ public UserManager @UserManager
> /*  2 */ {
> /*  3 */     get 
> /*  4 */     {
> /*  5 */         lock (this)
> /*  6 */         {
> /*  7 */             return this.m_userManager ??
> /*  8 */                    (this.m_userManager = new UserManager(Session.Instance.ApiClient,
> /*  9 */                        new Database<User>(DBUtils.DatabaseLocation)));
> /* 10 */         }
> /* 11 */     }
> /* 11 */ }

`this` shouldn't be null, thus line 7 shouldn't produce an NRE. That leaves line 8, which has two subexpressions:

* Session.Instance.ApiClient
* new Database<User>(DBUtils.DatabaseLocation)

The latter expression *cannot* produce an NRE *rooted* in get_PsonarUserManager(). DBUtils.DatabaseLocation is a static property; were it to throw, the stack trace would contain DBUtils.get_DatabaseLocation(), and it doesn't. The Database<User>() constructor could throw, but likewise the stack trace would contain Database`1..ctor(), and it doesn't.

Therefore the latter expression isn't producing the NRE.

Which brings us to Session.Instance.ApiClient: if Session is null, or Session.Instance is null, then the observed NullReferenceException with the observed stack trace could be produced.

---

@Jakub: Please double-check that the property implementation in Comment #2 is the correct property from Comment #0. The "get_PsonarUserManager()" vs. "get_UserManager()" difference is troubling.

@Jakub: Please double-check that neither Session nor Session.Instance are null.
Comment 6 Jakub Holovsky 2016-05-03 09:45:28 UTC
@Jonathan, thank you for your reply, it seems that the issue will be somewhere else. I am able with the configuration I wrote above create quite a few different exceptions. It seems very inconsistent and unpredictable.

These are the three latest exceptions that I am able to create when performing the same action on API 23.

Two of them are coming from sqllite-net, I think that the first one might be related to it as well.

05-03 04:07:51.607 I/MonoDroid( 4123): UNHANDLED EXCEPTION:
05-03 04:07:51.607 I/MonoDroid( 4123): System.NullReferenceException: Object reference not set to an instance of an object
05-03 04:07:51.607 I/MonoDroid( 4123): at SQLite.SQLiteConnection..ctor (string,SQLite.SQLiteOpenFlags,bool) [0x00000] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Common\SQLite\SQLite.cs:130
05-03 04:07:51.607 I/MonoDroid( 4123): at SQLite.SQLiteConnection..ctor (string,bool) [0x00000] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Common\SQLite\SQLite.cs:162
05-03 04:07:51.607 I/MonoDroid( 4123): at Psonar.Apps.Common.Data.Database`1<Psonar.Apps.Common.Models.User>..ctor (string) <0x00033>
05-03 04:07:51.607 I/MonoDroid( 4123): at Psonar.Apps.Droid.PayPerPlay.PsonarApplication.get_UserManager () [0x0000f] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\PsonarApplication.cs:433
05-03 04:07:51.607 I/MonoDroid( 4123): at Psonar.Apps.Droid.PayPerPlay.BaseActivity.get_PsonarUserManager () [0x0000d] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\UI\BaseActivity.cs:35
05-03 04:07:51.607 I/MonoDroid( 4123): at Psonar.Apps.Droid.PayPerPlay.LoginActivity.HandleLogin (object,System.EventArgs) [0x000cb] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\UI\LoginActivity.cs:101
05-03 04:07:51.607 I/MonoDroid( 4123): at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1938
05-03 04:07:51.607 I/MonoDroid( 4123): at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1903
05-03 04:07:51.607 I/MonoDroid( 4123): at (wrapper dynamic-method) object.57eccf38-fc5a-4470-bdd8-4d415792fe54 (intptr,intptr,intptr) <IL 0x00017, 0x00027>
05-03 04:07:51.613 D/Mono    ( 4123): Assembly Ref addref Psonar.Apps.Droid.PayPerPlay[0xe803c960] -> Xamarin.Auth.Android[0xe803e0a0]: 2
05-03 04:07:51.613 D/Mono    ( 4123): Assembly Ref addref Xamarin.Auth.Android[0xe803e0a0] -> mscorlib[0xe803cae0]: 34
05-03 04:07:51.613 D/Mono    ( 4123): Assembly Ref addref Xamarin.Auth.Android[0xe803e0a0] -> Mono.Android[0xf3102840]: 19
05-03 04:07:51.618 D/Mono    ( 4123): Assembly Ref addref Xamarin.Auth.Android[0xe803e0a0] -> System[0xd7eeae20]: 8
The thread 'Unknown' (0x8) has exited with code 0 (0x0).
05-03 04:07:51.661 D/Mono    ( 4123): Assembly Ref addref Mono.Android[0xf3102840] -> System[0xd7eeae20]: 9
Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object

05-03 04:46:41.749 E/chromium( 3867): ### WebView Version 40 (1808730-x86) (code 400007)
05-03 04:46:41.756 D/Mono    ( 3867): DllImport attempting to load: '/system/lib/liblog.so'.
05-03 04:46:41.756 D/Mono    ( 3867): DllImport loaded library '/system/lib/liblog.so'.
05-03 04:46:41.756 D/Mono    ( 3867): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
05-03 04:46:41.756 D/Mono    ( 3867): Searching for '__android_log_print'.
05-03 04:46:41.757 I/MonoDroid( 3867): at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_v05-03 04:46:41.756 D/Mono    ( 3867): Probing '__android_log_print'.
05-03 04:46:41.756 D/Mono    ( 3867): Found as '__android_log_print'.
05-03 04:46:41.757 I/MonoDroid( 3867): UNHANDLED EXCEPTION:
05-03 04:46:41.757 I/MonoDroid( 3867): System.NullReferenceException: Object reference not set to an instance of an object
05-03 04:46:41.757 I/MonoDroid( 3867): at Psonar.Apps.Droid.PayPerPlay.BaseActivity.get_PsonarUserManager () [0x00000] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\UI\BaseActivity.cs:33
05-03 04:46:41.757 I/MonoDroid( 3867): at Psonar.Apps.Droid.PayPerPlay.LoginActivity.HandleLogin (object,System.EventArgs) [0x000cb] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\UI\LoginActivity.cs:101
05-03 04:46:41.757 I/MonoDroid( 3867): at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1938
05-03 04:46:41.757 I/MonoDroid( 3867): at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1903
05-03 04:46:41.757 I/MonoDroid( 3867): at (wrapper dynamic-method) object.3c5177ee-69d2-46f2-bd25-b9c3c2b084a6 (intptr,intptr,intptr) <IL 0x00017, 0x00027>
05-03 04:46:41.763 D/Mono    ( 3867): Assembly Ref addref Psonar.Apps.Droid.PayPerPlay[0xf2d44780] -> Xamarin.Auth.Android[0xe7e3ec80]: 2
05-03 04:46:41.764 D/Mono    ( 3867): Assembly Ref addref Xamarin.Auth.Android[0xe7e3ec80] -> mscorlib[0xf2d44840]: 34
05-03 04:46:41.764 D/Mono    ( 3867): Assembly Ref addref Xamarin.Auth.Android[0xe7e3ec80] -> Mono.Android[0xf2d44e40]: 19
05-03 04:46:41.769 D/Mono    ( 3867): Assembly Ref addref Xamarin.Auth.Android[0xe7e3ec80] -> System[0xd7f07dc0]: 8
05-03 04:46:41.812 D/Mono    ( 3867): Assembly Ref addref Mono.Android[0xf2d44e40] -> System[0xd7f07dc0]: 9
The thread 'Unknown' (0x8) has exited with code 0 (0x0).

05-03 05:34:44.450 I/MonoDroid( 5997): UNHANDLED EXCEPTION:
05-03 05:34:44.451 I/MonoDroid( 5997): System.NullReferenceException: Object reference not set to an instance of an object
05-03 05:34:44.451 I/MonoDroid( 5997): at System.Random..ctor (int) [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/mono/external/referencesource/mscorlib/system/random.cs:38
05-03 05:34:44.451 I/MonoDroid( 5997): at System.Random..ctor () [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/mono/external/referencesource/mscorlib/system/random.cs:53
05-03 05:34:44.451 I/MonoDroid( 5997): at SQLite.SQLiteConnection..ctor (string,SQLite.SQLiteOpenFlags,bool) [0x0001d] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Common\SQLite\SQLite.cs:136
05-03 05:34:44.451 I/MonoDroid( 5997): at SQLite.SQLiteConnection..ctor (string,bool) [0x00000] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Common\SQLite\SQLite.cs:162
05-03 05:34:44.451 I/MonoDroid( 5997): at Psonar.Apps.Common.Data.Database`1<Psonar.Apps.Common.Models.User>..ctor (string) <0x00033>
05-03 05:34:44.451 I/MonoDroid( 5997): at Psonar.Apps.Droid.PayPerPlay.PsonarApplication.get_UserManager () [0x0000f] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\PsonarApplication.cs:433
05-03 05:34:44.451 I/MonoDroid( 5997): at Psonar.Apps.Droid.PayPerPlay.BaseActivity.get_PsonarUserManager () [0x0000d] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\UI\BaseActivity.cs:35
05-03 05:34:44.451 I/MonoDroid( 5997): at Psonar.Apps.Droid.PayPerPlay.LoginActivity.HandleLogin (object,System.EventArgs) [0x000cb] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\UI\LoginActivity.cs:101
05-03 05:34:44.451 I/MonoDroid( 5997): at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1938
05-03 05:34:44.451 I/MonoDroid( 5997): at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1903
05-03 05:34:44.451 I/MonoDroid( 5997): at (wrapper dynamic-method) object.cf22de32-72b8-4fc7-9c8a-a1497b04dffd (intptr,intptr,intptr) <IL 0x00017, 0x00027>

What caught my eye the most is the last exception:

05-03 05:34:44.451 I/MonoDroid( 5997): at System.Random..ctor (int) [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/mono/external/referencesource/mscorlib/system/random.cs:38
05-03 05:34:44.451 I/MonoDroid( 5997): at System.Random..ctor () [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/mono/external/referencesource/mscorlib/system/random.cs:53

I think that we can rename this issue to somewhere else as I do not longer believe it is triggered by System.IO.Path.Combine
Comment 7 Jakub Holovsky 2016-05-03 12:12:33 UTC
I was able to create two more exceptions while preforming the same action:

05-03 07:00:19.174 E/mono    ( 6611): 
05-03 07:00:19.174 E/mono    ( 6611): Unhandled Exception:
05-03 07:00:19.174 E/mono    ( 6611): System.NullReferenceException: Object reference not set to an instance of an object
05-03 07:00:19.174 E/mono    ( 6611): at Android.Runtime.JNIEnv.WaitForBridgeProcessing () [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:256
05-03 07:00:19.174 E/mono    ( 6611): at (wrapper dynamic-method) object.121c3aee-9fac-478d-be83-a48f7ef56831 (intptr,intptr) <IL 0x00000, 0x0000b>
05-03 07:00:19.174 E/mono    ( 6611): at (wrapper native-to-managed) object.121c3aee-9fac-478d-be83-a48f7ef56831 (intptr,intptr) <IL 0x00022, 0x00073>
05-03 07:00:19.174 E/mono    ( 6611): 
05-03 07:00:19.174 E/mono-rt ( 6611): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object

05-03 07:06:55.381 I/MonoDroid( 7132): UNHANDLED EXCEPTION:
05-03 07:06:55.381 I/MonoDroid( 7132): System.NullReferenceException: Object reference not set to an instance of an object
05-03 07:06:55.381 I/MonoDroid( 7132): at System.Environment.GetFolderPath (System.Environment/SpecialFolder,System.Environment/SpecialFolderOption) [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/corlib/System/Environment.cs:560
05-03 07:06:55.381 I/MonoDroid( 7132): at System.Environment.GetFolderPath (System.Environment/SpecialFolder) [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/corlib/System/Environment.cs:549
05-03 07:06:55.381 I/MonoDroid( 7132): at Psonar.Apps.Droid.PayPerPlay.DBUtils.get_DatabaseLocation () [0x00001] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\Utilities\DBUtils.cs:23
05-03 07:06:55.381 I/MonoDroid( 7132): at Psonar.Apps.Droid.PayPerPlay.PsonarApplication.get_UserManager () [0x0000f] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\PsonarApplication.cs:433
05-03 07:06:55.381 I/MonoDroid( 7132): at Psonar.Apps.Droid.PayPerPlay.BaseActivity.get_PsonarUserManager () [0x0000d] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\UI\BaseActivity.cs:35
05-03 07:06:55.381 I/MonoDroid( 7132): at Psonar.Apps.Droid.PayPerPlay.LoginActivity.HandleLogin (object,System.EventArgs) [0x000cb] in E:\Dev\psonar\Source\Psonar.Apps\Psonar.Apps.Droid\Psonar.Apps.Droid.PayPerPlay\UI\LoginActivity.cs:101
05-03 07:06:55.381 I/MonoDroid( 7132): at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1938
05-03 07:06:55.381 I/MonoDroid( 7132): at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1903
05-03 07:06:55.381 I/MonoDroid( 7132): at (wrapper dynamic-method) object.ca3ca71f-5415-4c12-8354-fb8b87871974 (intptr,intptr,intptr) <IL 0x00017, 0x00027>
05-03 07:06:55.387 D/Mono    ( 7132): Assembly Ref addref Psonar.Apps.Droid.PayPerPlay[0xe7e3d960] -> Xamarin.Auth.Android[0xe7e3f280]: 2
05-03 07:06:55.387 D/Mono    ( 7132): Assembly Ref addref Xamarin.Auth.Android[0xe7e3f280] -> mscorlib[0xe7e3db40]: 34
05-03 07:06:55.387 D/Mono    ( 7132): Assembly Ref addref Xamarin.Auth.Android[0xe7e3f280] -> Mono.Android[0xf2d449c0]: 19
05-03 07:06:55.393 D/Mono    ( 7132): Assembly Ref addref Xamarin.Auth.Android[0xe7e3f280] -> System[0xd7f04dc0]: 8
05-03 07:06:55.453 D/Mono    ( 7132): Assembly Ref addref Mono.Android[0xf2d449c0] -> System[0xd7f04dc0]: 9
The thread 'Unknown' (0x8) has exited with code 0 (0x0).
Unhandled Exception:
Comment 8 Jonathan Pryor 2016-05-05 12:46:18 UTC
What Xamarin.Android version is this? As per the stack traces, it's "monodroid/53fce373", which should to Xamarin.Android 5.1.

We're currently on Xamarin.Android 6.0, and 6.1 is in beta...

Have you considered upgrading?

Aside: If you prefix your lines with `> `, bugzilla will disable line wrapping, which makes for easier to read stack traces.

> 5-03 07:00:19.174 E/mono    ( 6611): System.NullReferenceException: Object reference not set to an instance of an object
> 05-03 07:00:19.174 E/mono    ( 6611): at Android.Runtime.JNIEnv.WaitForBridgeProcessing () [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:256

This makes *no sense at all*. JNIEnv.cs:256 is:

https://github.com/xamarin/xamarin-android/blob/3885fcc/src/Mono.Android/Android.Runtime/JNIEnv.cs#L323

It's accessing a static `bool` variable. How can that possibly throw a NullReferenceException?

(My mind. It is blown.)

The NullReferenceException from Environment.GetFolderPath() is similarly crazy:

https://github.com/mono/mono/blob/5ab4c0d099a69de2a2ef5d1cf8d83e78df4d6af8/mcs/class/corlib/System/Environment.cs#L560

That's invoking a static method from within a static method. How can that possibly throw an NRE?

Something is seriously FUBAR here, and you're on a product commit that dates to August 2015.

Please try upgrading.
Comment 9 Jakub Holovsky 2016-05-09 11:29:48 UTC
Hello Jonathan, thank you for your reply. I know, it does not make much sense at all. We will do an upgrade as soon as we can. I will post my findings here afterwards.
Comment 10 Cody Beyer (MSFT) 2017-08-21 21:38:17 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!