Xamarin.Forms.Platform.Android.Platform+DefaultRenderer from native handle

冷暖自知 提交于 2019-12-24 20:10:11

问题


I am developing app on android using xamarin forms. Since few days, I am getting below issue.

CurrentDomainOnUnhandledException ---> System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.Platform+DefaultRenderer from native handle 0xbeb0861c (key_handle 0xb3a225b). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.Platform+DefaultRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown. 05-02 14:36:57.973 I/mono-stdout(16628): System.Exception: CurrentDomainOnUnhandledException ---> System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.Platform+DefaultRenderer from native handle 0xbeb0861c (key_handle 0xb3a225b). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.Platform+DefaultRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown. --- End of inner exception stack trace --- 05-02 14:36:57.975 I/mono-stdout(16628):
--- End of inner exception stack trace --- at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00054] in :0 05-02 14:36:57.978 I/mono-stdout(16628): at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00054] in :0 at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in :0 05-02 14:36:57.980 I/mono-stdout(16628): at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in :0 --- End of inner exception stack trace --- 05-02 14:36:57.982 I/mono-stdout(16628): --- End of inner exception stack trace --- at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017d] in :0 05-02 14:36:57.984 I/mono-stdout(16628): at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017d] in :0 at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000b9] in :0 05-02 14:36:57.986 I/mono-stdout(16628): at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000b9] in :0 at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in :0 05-02 14:36:57.988 I/mono-stdout(16628): at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in :0

at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in :0 at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in :0 at Android.Views.View.n_DispatchTouchEvent_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x00000] in :0 at (wrapper dynamic-method) System.Object:3943ee27-49d5-404c-b2ef-5f107b52e084 (intptr,intptr,intptr) --- End of inner exception stack trace


回答1:


  1. I did so much research work on this issue. I understood that when system is invoking GC, it collects all objects like managed,unmanaged,peer objects. peer objects are native objects used in PCL. When these objects gets null, system does not know that it required to create these objects again. So should tell the system that you need to create the objects.

It can be done by just adding constructor to all custom renderers. public CustomEntryImageRenderer(IntPtr handle, JniHandleOwnership transfer) { }

  1. I changed all my controls to custom renderers and added this constructor for all renderers.

  2. If you are using any rg plugins popup, set animation to false.

4.Add below override method to your custom renderer listview.

    protected override void Dispose(bool disposing)
    {

        Xamarin.Forms.Device.BeginInvokeOnMainThread(base.Dispose);

    }


来源:https://stackoverflow.com/questions/50131073/xamarin-forms-platform-android-platformdefaultrenderer-from-native-handle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!