DLToolkit.Forms.Controls icon indicating copy to clipboard operation
DLToolkit.Forms.Controls copied to clipboard

TagEntry in xf3.2 crash

Open jxnkwlp opened this issue 6 years ago • 2 comments

in xamarin forms 3.2, when touch keybord blank space , the app crash . and throw errors: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.EntryRenderer from native handle 0x7fef11dcb4 (key_handle 0x64dfe53).

This error is xamarin.forms ??

Thanks .

jxnkwlp avatar Oct 14 '18 11:10 jxnkwlp

The very bad error. This can happen for many reasons

https://stackoverflow.com/questions/10593022/monodroid-error-when-calling-constructor-of-custom-view-twodscrollview/10603714#10603714

vlkam avatar Oct 14 '18 15:10 vlkam

BTW after upgrading the Xamarin.Forms to the latest version (Version >=3.2), my app was crashing with this and similar following exception,

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FormsEditText from native handle 0xbff9dd3c (key_handle 0x6ff142a). occurred

And I managed to fix this by making the changes to the TagEntryRenderer as below,

[assembly: ExportRenderer(typeof(TagEntry), typeof(TagEntryRenderer))]
namespace MyProject.Android.Renderers
{
    public class TagEntryRenderer : EntryRenderer
    {
        public static void Init()
        {
#pragma warning disable 0219
            var dummy = new TagEntryRenderer(MainActivity.Context);
#pragma warning restore 0219
        }

        public TagEntryRenderer(Context context) : base(context)
        {
        }

        public TagEntryRenderer(Context context, IAttributeSet attrs) : base(context)
        {
        }

        public TagEntryRenderer(Context context, IAttributeSet attrs, int defStyle) : base(context)
        {
        }
        public TagEntryRenderer(IntPtr a, JniHandleOwnership b) : base(MainActivity.Context)
        {
        }
		
		//Please see comment below
        protected override FormsEditText CreateNativeControl()
        {
            return new FormsEditTextExtended(MainActivity.Context);
        }
    }

    /*
     * In order to fix the exception below, we're using this workaround.
     * This workaround was not required in XF3.1 but on latest XF versions it causes issues
     * System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.AnAndroid.FormsEditText from native handle 0xbff9dd3c (key_handle 0x6ff142a). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.AnAndroid.FormsEditText::.ctor(System.IntPtr, AnAndroid.Runtime.JniHandleOwnership)
     */
    public class FormsEditTextExtended : FormsEditText
    {
        public FormsEditTextExtended(Context context) : base(context)
        {
        }

        public FormsEditTextExtended(IntPtr a, JniHandleOwnership b) : base(MainActivity.Context)
        {
        }
    }
}

mwasim avatar Jan 29 '19 11:01 mwasim