Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes on launch due to mono.android code throws "System.ArgumentException: Handle must be valid." #5628

Closed
anasonov1992 opened this issue Feb 15, 2021 · 1 comment
Assignees
Labels
Area: Mono.Android Issues with the Android API binding (Mono.Android.dll).

Comments

@anasonov1992
Copy link

anasonov1992 commented Feb 15, 2021

Steps to Reproduce

  1. Build release bundle
  2. Upload to Google Play Console internal Test Track
  3. Wait for Pre-Launch Tests to report crashes

In our crash reports we have an exception stacktrace:

**Fatal        AndroidEnvironment - Unhandled Exception Raiser:**
Java.Lang.RuntimeException: Binary XML file line #1: Error inflating class ilive.uicontrols.droid.QuickActionsView ---> Java.Lang.ReflectiveOperationException: Exception of type 'Java.Lang.ReflectiveOperationException' was thrown. ---> **System.ArgumentException: Handle must be valid.**
Parameter name: instance
  at Java.Interop.JniEnvironment+Types.GetObjectClass (Java.Interop.JniObjectReference instance) <0x7c36cd7420 + 0x00138> in <6e097fe6d077433691fc949b02ec9c9c>:0 
  at Android.Runtime.JNIEnv.GetObjectClass (System.IntPtr jobject) <0x7c376073b4 + 0x0002f> in <9c8f4d92a36e41be98c4681d2861b946>:0 
  at Android.Runtime.JNIEnv.GetClassNameFromInstance (System.IntPtr jobject) <0x7c376009cc + 0x00033> in <9c8f4d92a36e41be98c4681d2861b946>:0 
  at Java.Interop.TypeManager.n_Activate (System.IntPtr jnienv, System.IntPtr jclass, System.IntPtr typename_ptr, System.IntPtr signature_ptr, System.IntPtr jobject, System.IntPtr parameters_ptr) <0x7c3766b5b8 + 0x0046f> in <9c8f4d92a36e41be98c4681d2861b946>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr,intptr,intptr,intptr,intptr)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) <0x7c36cce080 + 0x00147> in <6e097fe6d077433691fc949b02ec9c9c>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) <0x7c36cb36ec + 0x0009b> in <6e097fe6d077433691fc949b02ec9c9c>:0 
  at Android.Views.LayoutInflater.CreateView (System.String name, System.String prefix, Android.Util.IAttributeSet attrs) <0x7c374c7958 + 0x0011f> in <9c8f4d92a36e41be98c4681d2861b946>:0 
  at MvvmCross.Platforms.Android.Binding.Views.MvxLayoutInflater.CreateCustomViewInternal (Android.Views.View parent, Android.Views.View view, System.String name, Android.Content.Context viewContext, Android.Util.IAttributeSet attrs) <0x7c3590eb50 + 0x002d3> in <084ff9503a0f4edf88eae8fc5170f9cb>:0 
  at MvvmCross.Platforms.Android.Binding.Views.MvxLayoutInflater+PrivateFactoryWrapper2.OnCreateView (Android.Views.View parent, System.String name, Android.Content.Context context, Android.Util.IAttributeSet attrs) <0x7c35852900 + 0x00113> in <084ff9503a0f4edf88eae8fc5170f9cb>:0 
  at Android.Views.LayoutInflater+IFactory2Invoker.n_OnCreateView_Landroid_view_View_Ljava_lang_String_Landroid_content_Context_Landroid_util_AttributeSet_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_parent, System.IntPtr native_name, System.IntPtr native_context, System.IntPtr native_attrs) <0x7c374c940c + 0x000e3> in <9c8f4d92a36e41be98c4681d2861b946>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.45(intptr,intptr,intptr,intptr,intptr,intptr)
  --- End of managed Java.Lang.RuntimeException stack trace ---
android.view.InflateException: Binary XML file line #1: Error inflating class ilive.uicontrols.droid.QuickActionsView
Caused by: java.lang.reflect.InvocationTargetException
	at java.lang.reflect.Constructor.newInstance0(Native Method)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
	at android.view.LayoutInflater.createView(LayoutInflater.java:647)
	at mvvmcross.platforms.android.binding.views.MvxLayoutInflater_PrivateFactoryWrapper2.n_onCreateView(Native Method)
	at mvvmcross.platforms.android.binding.views.MvxLayoutInflater_PrivateFactoryWrapper2.onCreateView(MvxLayoutInflater_PrivateFactoryWrapper2.java:32)
	at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
	at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
	at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
	at mvvmcross.platforms.android.binding.views.MvxLayoutInflater.n_inflate(Native Method)
	at mvvmcross.platforms.android.binding.views.MvxLayoutInflater.inflate(MvxLayoutInflater.java:50)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
	at crc6417ea2e2826b8b2ac.BaseFragment.n_onCreateView(Native Method)
	at crc6417ea2e2826b8b2ac.BaseFragment.onCreateView(BaseFragment.java:40)
	at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
	at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
	at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
	at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
	at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
	at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
	at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
	at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
	at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
	at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
	at android.os.Handler.handleCallback(Handler.java:873)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:193)
	at android.app.ActivityThread.main(ActivityThread.java:6692)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)	
**Caused by: android.runtime.JavaProxyThrowable: System.ArgumentException: Handle must be valid.
Parameter name: instance
  at Java.Interop.JniEnvironment+Types.GetObjectClass (Java.Interop.JniObjectReference instance) <0x7c36cd7420 + 0x00138> in <6e097fe6d077433691fc949b02ec9c9c>:0 
  at Android.Runtime.JNIEnv.GetObjectClass (System.IntPtr jobject) <0x7c376073b4 + 0x0002f> in <9c8f4d92a36e41be98c4681d2861b946>:0 
  at Android.Runtime.JNIEnv.GetClassNameFromInstance (System.IntPtr jobject) <0x7c376009cc + 0x00033> in <9c8f4d92a36e41be98c4681d2861b946>:0 
  at Java.Interop.TypeManager.n_Activate (System.IntPtr jnienv, System.IntPtr jclass, System.IntPtr typename_ptr, System.IntPtr signature_ptr, System.IntPtr jobject, System.IntPtr parameters_ptr) <0x7c3766b5b8 + 0x0046f> in <9c8f4d92a36e41be98c4681d2861b946>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr,intptr,intptr,intptr,intptr)
	at mono.android.TypeManager.n_activate(Native Method)
	at mono.android.TypeManager.Activate(TypeManager.java:7)
	at ilive.uicontrols.droid.QuickActionsView.<init>(QuickActionsView.java:30)**

QuickActionsView is our custom control registered (by Register attribute) and used in XML as ilive.uicontrols.droid.QuickActionsView (see files in attached archive: QuickActionsView.cs, generated QuickActionsView.java and QuickActionsView_Usage.axml).
QuickActionsView.zip

I've found a few similar issues with "System.ArgumentException: Handle must be valid." error.
But I don't realize whether the issue was solved or not there.
jamesmontemagno/SettingsPlugin#152
xamarin/Essentials#1301

Most of the posts suggest you can suppress the error by changing the GC bridge implementation to the Old version instead of Tarjan by setting an environment variable. For example:
https://stackoverflow.com/questions/61225706/strange-handle-must-be-valid-exception-in-dialog
https://stackoverflow.com/questions/51022450/xamarin-android-cant-set-cg-bridge-to-old-mode-mono-gc-params-bridge-implemen?noredirect=1&lq=1

But I'm not sure how to check my current GC version by VS tools. I don't see anything in my logcat or build output to indicate it's using one bridge or the other. What is the right way to check this?

Expected Behavior

App launches successfully.

Actual Behavior

Crashes during Splash Screen

Version Information

=== Visual Studio Community 2019 for Mac ===

Version 8.8.2 (build 41)
Installation UUID: 617a1f42-f36f-491b-8f59-449405eeefe5
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

Package version: 612000107

=== Mono Framework MDK ===

Runtime:
Mono 6.12.0.107 (2020-02/a22ed3f094e) (64-bit)
Package version: 612000107

=== Roslyn (Language Service) ===

3.8.0-5.20519.18+4c195c3ac1974edcefa76774d7a59a2350ec55fa

=== NuGet ===

Version: 5.8.0.6860

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.100/Sdks
SDK Versions:
5.0.100
3.1.403
3.1.200
3.1.102
3.1.101
3.1.100
3.0.101
3.0.100
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
5.0.0
3.1.9
3.1.2
3.1.1
3.1.0
3.0.1
3.0.0
2.1.23
2.1.16
2.1.15
2.1.14
2.1.13

=== .NET Core 3.1 SDK ===

SDK: 3.1.403

=== Xamarin.Profiler ===

Version: 1.6.12.29
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

A valid Xcode installation was not found at the configured location: '/Applications/Xcode.app'

=== Xamarin.Mac ===

Version: 7.0.0.15 (Visual Studio Community)
Hash: 87a1b18d8
Branch: d16-8
Build date: 2020-11-16 21:39:40-0500

=== Xamarin.iOS ===

Version: 14.6.0.15 (Visual Studio Community)
Hash: 87a1b18d8
Branch: d16-8
Build date: 2020-11-16 21:39:41-0500

=== Xamarin Designer ===

Version: 16.8.0.507
Hash: e87b24884
Branch: remotes/origin/d16-8
Build date: 2020-10-29 00:31:38 UTC

=== Xamarin.Android ===

Version: 11.1.0.17 (Visual Studio Community)
Commit: xamarin-android/d16-8/c0e2b8e
Android SDK: /Users/ddp/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
None installed

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.4
SDK Build Tools Version: 29.0.2

Build Information:
Mono: be2226b
Java.Interop: xamarin/java.interop/d16-8@79d9533
ProGuard: Guardsquare/proguard@ebe9000
SQLite: xamarin/sqlite@1a3276b
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/ddp/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.8.0.32
Hash: 01a7774
Branch: remotes/origin/d16-8
Build date: 2020-10-13 23:32:30 UTC

=== Android Device Manager ===

Version: 16.8.0.45
Hash: fc0af5f
Branch: remotes/origin/d16-8
Build date: 2020-10-13 23:32:54 UTC

=== Build Information ===

Release ID: 808020041
Git revision: dba789c00d07d6923cce74016b7e406526d683da
Build date: 2020-11-23 04:40:23-05
Build branch: release-8.8
Xamarin extensions: dba789c00d07d6923cce74016b7e406526d683da

=== Operating System ===

Mac OS X 10.14.6
Darwin 18.7.0 Darwin Kernel Version 18.7.0
Mon Aug 31 20:53:32 PDT 2020
root:xnu-4903.278.44~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

DeepClean 1.2.5

Log File

@anasonov1992 anasonov1992 added the Area: Mono.Android Issues with the Android API binding (Mono.Android.dll). label Feb 15, 2021
@grendello grendello added this to the Under Consideration milestone Feb 16, 2021
@jpobst
Copy link
Contributor

jpobst commented May 15, 2024

With support for Classic Xamarin.Android ended May 1st, 2024, this issue is likely no longer relevant.

If this still persists in .NET 8+, please open a new issue with updated information based on net8.0-android or greater. Please include a link to this issue for context.

@jpobst jpobst closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: Mono.Android Issues with the Android API binding (Mono.Android.dll).
Projects
None yet
Development

No branches or pull requests

4 participants