(Only applicable on Android)
When Application.MainPage is a Singleton TabbedPage using a TabbedPageRenderer (example code, below), Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal throws the following exceptions:
System.NotSupportedException: Unable to activate instance of type XamarinFormsSingletonRepro.Droid.SingletonTabbedPageRenderer from native handle System.MissingMethodException: No constructor found for XamarinFormsSingletonRepro.Droid.SingletonTabbedPageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)This is the same error from #4325 and continues to happen in v3.6.0264807.
Sample Code, TabbedPage
The complete sample reproduction code using Xamarin.Forms v3.6.0.0264807 can be found here: https://github.com/brminnick/XamarinFormsSingletonRepro
public class App : Application
{
public App() => MainPage = SingletonTabbedPage.Instance;
}
public class SingletonTabbedPage : TabbedPage
{
readonly static Lazy<SingletonTabbedPage> _instanceHolder = new Lazy<SingletonTabbedPage>(() => new SingletonTabbedPage());
public static SingletonTabbedPage Instance => _instanceHolder.Value;
}
Sample Code, TabbedPageRenderer
using Xamarin.Forms;
using Android.Content;
using Xamarin.Forms.Platform.Android.AppCompat;
using XamarinFormsSingletonRepro;
using XamarinFormsSingletonRepro.Droid;
[assembly: ExportRenderer(typeof(SingletonTabbedPage), typeof(SingletonTabbedPageRenderer))]
namespace XamarinFormsSingletonRepro.Droid
{
public class SingletonTabbedPageRenderer : TabbedPageRenderer
{
public SingletonTabbedPageRenderer(Context context) : base(context)
{
}
}
}
Stack Trace
System.NotSupportedException: Unable to activate instance of type XamarinFormsSingletonRepro.Droid.SingletonTabbedPageRenderer from native handle 0x69 (key_handle 0x8858560). ---> System.MissingMethodException: No constructor found for XamarinFormsSingletonRepro.Droid.SingletonTabbedPageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
at Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
at java.lang.Error: Java callstack:
at at mono.java.lang.RunnableImplementor.n_run(Native Method)
at at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
at at android.os.Handler.handleCallback(Handler.java:873)
at at android.os.Handler.dispatchMessage(Handler.java:99)
at at android.os.Looper.loop(Looper.java:193)
at at android.app.ActivityThread.main(ActivityThread.java:6669)
at at java.lang.reflect.Method.invoke(Native Method)
at at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
--- End of inner exception stack trace ---
at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00055] in <2960acf2eeb24d88b5230e1e8afbdc2e>:0
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00116] in <2960acf2eeb24d88b5230e1e8afbdc2e>:0
--- End of inner exception stack trace ---
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00182] in <2960acf2eeb24d88b5230e1e8afbdc2e>:0
at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000c1] in <2960acf2eeb24d88b5230e1e8afbdc2e>:0
at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <2960acf2eeb24d88b5230e1e8afbdc2e>:0
at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <2960acf2eeb24d88b5230e1e8afbdc2e>:0
at Android.Views.ViewGroup.GetChildAt (System.Int32 index) [0x00036] in <2960acf2eeb24d88b5230e1e8afbdc2e>:0
at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x0001a] in D:\a\1\sXamarin.Forms.Platform.Android\AppCompat\Platform.cs:301
at Xamarin.Forms.Platform.Android.AppCompat.Platform+<>c__DisplayClass36_0.b__0 () [0x0001f] in D:\a\1\sXamarin.Forms.Platform.Android\AppCompat\Platform.cs:269
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <2960acf2eeb24d88b5230e1e8afbdc2e>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <2960acf2eeb24d88b5230e1e8afbdc2e>:0
at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.27(intptr,intptr)

https://github.com/brminnick/XamarinFormsSingletonRepro
(From App Center Crash)

=== Visual Studio Enterprise 2019 for Mac ===
Version 8.0.2 (build 23)
Installation UUID: 4ac69d79-c034-474c-9629-20084c942d3c
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.6.0.2 (d16-0 / 040682909)
Package version: 518010003
=== Mono Framework MDK ===
Runtime:
Mono 5.18.1.3 (2018-08/fdb26b0a445) (64-bit)
Package version: 518010003
=== NuGet ===
Version: 4.8.2.5835
=== .NET Core ===
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
3.0.0-preview3-27503-5
3.0.0-preview-27324-5
3.0.0-preview-27122-01
2.2.0
2.2.0-preview3-27014-02
2.1.9
2.1.8
2.1.6
2.1.2
2.1.1
2.0.6
2.0.5
1.1.10
1.0.13
SDK: /usr/local/share/dotnet/sdk/2.2.100/Sdks
SDK Versions:
2.2.100
2.1.505
2.1.504
2.1.500
2.1.302
2.1.301
2.1.101
2.1.4
1.1.11
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.18.1/lib/mono/msbuild/15.0/bin/Sdks
=== Xamarin.Profiler ===
Version: 1.6.9
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
=== Updater ===
Version: 11
=== Xamarin.Android ===
Version: 9.2.0.5 (Visual Studio Enterprise)
Android SDK: /Users/bramin/Library/Android/sdk
Supported Android versions:
6.0 (API level 23)
7.0 (API level 24)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.2
SDK Build Tools Version: 28.0.3
Build Information:
Mono: mono/mono/2018-08-rc@5ad371dab1b
Java.Interop: xamarin/java.interop/d16-0@c987483
LibZipSharp: grendello/LibZipSharp/master@44de300
LibZip: nih-at/libzip/rel-1-5-1@b95cf3f
MXE: xamarin/mxe/xamarin@b9cbb535
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.26.0@325e91a
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-0@0a7edd6
=== Microsoft Mobile OpenJDK ===
Java SDK: /Users/bramin/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
=== Android Device Manager ===
Version: 1.2.0.14
Hash: 86df26f
Branch: remotes/origin/d16-0
Build date: 2019-04-05 16:58:56 UTC
=== Apple Developer Tools ===
Xcode 10.2 (14490.120)
Build 10E125
=== Xamarin.Mac ===
Version: 5.8.0.0 (Visual Studio Enterprise)
Hash: 0aa84521
Branch: d16-0
Build date: 2019-04-02 16:01:19-0400
=== Xamarin.iOS ===
Version: 12.8.0.0 (Visual Studio Enterprise)
Hash: 0aa84521
Branch: d16-0
Build date: 2019-04-02 16:01:19-0400
=== Xamarin Designer ===
Version: 4.17.4.418
Hash: 3d086e814
Branch: remotes/origin/d16-0
Build date: 2019-04-01 09:20:10 UTC
=== Xamarin Inspector ===
Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1
=== Build Information ===
Release ID: 800020023
Git revision: c576bb008dfe54cdcf596237e09564ebd2da4343
Build date: 2019-04-06 10:06:46+00
Build branch: master
Xamarin extensions: 2c996830618e7cb8e8be97984d643eb86f122e8d
=== Operating System ===
Mac OS X 10.14.4
Darwin 18.5.0 Darwin Kernel Version 18.5.0
Mon Mar 11 20:40:32 PDT 2019
root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64
=== Enabled user installed extensions ===
NuGet Package Management Extensions 0.17
@kvpt may have some insight since it's a similar bug to the one solved in PR #4707.
From your issue description and reproduction I can confirm that my fix is related to that problem and is supposed to fix it.
On github when a Pull Request mention an issue, the issue is automatically close when the PR is merged.
But that only mean that the bug is fixed in the code and no that the bug is fixed in the last released version.
For now the fix seem to be included only on master branch, so i think it need to be backport to 3.6 branch and 4.0 branch to be available in the next releases.
For now, I use a custom version that I compiled myself which include this fix.
xamarin.forms.3.6.3.zip
Change the extension from .zip .to nupkg (because github limit extension type allowed).
To install the local package you can use the differents methods listed here.
If you can confirm that this version with the patch fix your issue, maybe the Xamarin Team will consider to backport the fix.
@brminnick Did 4.0.0-pre9 fix the issue? Thanks!
@samhouts v4.0.0-pre9 looks good!
This crash no longer happens when I run the sample repro on v4.0.0-pre9.