Xamarin Android and custom control: Unable to activate instance

0

I'm creating my custom control for a tag edit. I'm using Visual Studio 2019 and Xamarin Forms. It is working for UWP and iOS but in Android I have an error with the native renderer.

Error

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.EntryRenderer from native handle 0x7feca76624 (key_handle 0x95e8e41).

The output is:

04-24 10:10:11.382 W/InputMethodManager(17644): startInputReason = 4 04-24 10:10:11.415 I/HwSecImmHelper(17644): mSecurityInputMethodService is null 04-24 10:10:11.446 W/ResourceType(17644): No package identifier when getting name for resource number 0x00000000 04-24 10:10:11.448 W/View (17644): dispatchProvideAutofillStructure(): not laid out, ignoring 04-24 10:10:11.453 I/AssistStructure(17644): Flattened final assist data: 2444 bytes, containing 1 windows, 10 views 04-24 10:10:12.379 I/zygote64(17644): Do partial code cache collection, code=61KB, data=54KB 04-24 10:10:12.379 I/zygote64(17644): After code cache collection, code=61KB, data=54KB 04-24 10:10:12.379 I/zygote64(17644): Increasing code cache capacity to 256KB 04-24 10:10:14.160 W/zygote64(17644): JNI RegisterNativeMethods: attempt to register 0 native methods for md58432a647068b097f9637064b8985a5e0.FrameRenderer 04-24 10:10:14.220 W/InputMethodManager(17644): startInputReason = 4 04-24 10:10:14.259 W/InputMethodManager(17644): startInputReason = 4 04-24 10:10:14.260 I/zygote64(17644): Compiler allocated 5MB to compile void android.view.View.(android.content.Context, android.util.AttributeSet, int, int) 04-24 10:10:14.263 W/InputMethodManager(17644): startInputReason = 3 04-24 10:10:14.284 I/HwSecImmHelper(17644): mSecurityInputMethodService is null 04-24 10:10:14.379 I/zygote64(17644): Do full code cache collection, code=108KB, data=98KB 04-24 10:10:14.380 I/zygote64(17644): After code cache collection, code=101KB, data=74KB 04-24 10:10:14.568 D/Mono
(17644): Loading reference 6 of Mono.Android.dll asmctx DEFAULT, looking for System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e 04-24 10:10:14.570 D/Mono (17644): Image addref System.Runtime.Serialization[0x7e53d21780] (asmctx DEFAULT) -> System.Runtime.Serialization.dll[0x7e51894800]: 2mono_pe_file_map: Error opening file System.Runtime.Serialization.dll (3): No such file or directory

04-24 10:10:14.570 D/Mono (17644): Prepared to set up assembly 'System.Runtime.Serialization' (System.Runtime.Serialization.dll) 04-24 10:10:14.570 D/Mono (17644): Assembly System.Runtime.Serialization[0x7e53d21780] added to domain RootDomain, ref_count=1 04-24 10:10:14.572 D/Mono (17644): AOT: image 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "System.Runtime.Serialization.dll.so" not found 04-24 10:10:14.572 D/Mono (17644): AOT: image '/Users/builder/jenkins/workspace/xamarin-android-d16-0/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/lib/mono/aot-cache/arm64/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/Users/builder/jenkins/workspace/xamarin-android-d16-0/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/lib/mono/aot-cache/arm64/System.Runtime.Serialization.dll.so" not found 04-24 10:10:14.572 D/Mono (17644): Config attempting to parse: 'System.Runtime.Serialization.dll.config'. 04-24 10:10:14.572 D/Mono (17644): Config attempting to parse: '/Users/builder/jenkins/workspace/xamarin-android-d16-0/xamarin-android/external/mono/sdks/out/android-arm64-v8a-release/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'. 04-24 10:10:14.572 D/Mono (17644): Assembly Ref addref Mono.Android[0x7e56659a80] -> System.Runtime.Serialization[0x7e53d21780]: 2 04-24 10:10:14.573 D/Mono (17644): Loading reference 0 of System.Runtime.Serialization.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e 04-24 10:10:14.573 D/Mono (17644): Assembly Ref addref System.Runtime.Serialization[0x7e53d21780] -> mscorlib[0x7e77dc3c80]: 40 Loaded assembly: System.Runtime.Serialization.dll [External] Unhandled Exception:

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.EntryRenderer from native handle 0x7feca76624 (key_handle 0x95e8e41).

The component adds a runtime a new Entry in a Layout<View>. This is what I expect also in Android.

Result of TagEdit

The full source code of my component is on Github. The important part is here:

public class TagEntryView : Layout<View>, IDisposable
{
    TagEntry TagEntry;

    public TagEntryView()
    {
        PropertyChanged += TagEntryViewPropertyChanged;
        PropertyChanging += TagEntryViewPropertyChanging;

        TagEntry = new TagEntry();
        TagEntry.TextChanged += TagEntryTextChanged;
        Children.Add(TagEntry);
    }

    void TagEntryTextChanged(object sender, TextChangedEventArgs e)
    {
        if (TagSeparators != null)
        {
            if (TagSeparators.Any(e.NewTextValue.Contains))
            {
                string tag = e.NewTextValue;
                foreach (var item in TagSeparators)
                {
                    tag = tag.Replace(item, string.Empty);
                }

                if (TagValidatorFactory != null)
                {
                    var tagBindingContext = TagValidatorFactory(tag);
                    var tagEntry = sender as Entry;

                    if (tagBindingContext != null)
                    {
                        TagItems.Add(tagBindingContext);
                        tagEntry.Text = string.Empty;
                    }
                    else
                    {
                        tagEntry.Text = tag;
                    }

                    tagEntry.Focus();
                }
            }
        }
    }
}

For more details, I created two videos where I show in parallel what it is happing on Visual Studio and Android device.

Here what I'm doing on the Android device. Here debug in Visual Studio.

xamarin.forms
xamarin.android
visual-studio-2019
asked on Stack Overflow Apr 24, 2019 by Enrico • edited Apr 25, 2019 by Enrico

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0