Skip to content

TypeLoadException when registering TextChanged event on TextView #7097

@tipa

Description

@tipa

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

VS 2022 17.2.4, Xamarin.Android 12.3.3.3

Description

var filterBox = FindViewById<TextInputEditText>(Resource.Id.filterBox);
filterBox.TextChanged += (s, e) =>{ }; // <- crashes when building in Release mode

This problem has been previously reported here: #3263

Example app: AndroidApp1.zip

Steps to Reproduce

  • Create new Xamarin project, I also added the latest Google Material SDK, not sure if that is of relevance
  • Add Textview in xml layout and register TextChanged event on it in code
  • Build in Release mode, app crashes

Did you find any workaround?

Yes, adding a LinkDescription.xml with the following content resolves the issue. This workaround was posted here:

<?xml version="1.0" encoding="utf-8" ?>
<linker>
  <assembly fullname="Mono.Android">
    <type fullname="Android.Text.ITextWatcherInvoker" preserve="all" />
  </assembly>
</linker>

Relevant log output

    android.runtime.JavaProxyThrowable: System.TypeLoadException: Could not load type '{0}' from assembly '{1}'., Android.Text.ITextWatcherInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
        at System.RuntimeTypeHandle.GetTypeByName(String , Boolean , Boolean , StackCrawlMark& , Boolean )
        at System.RuntimeType.GetType(String , Boolean , Boolean , StackCrawlMark& )
        at System.Type.GetType(String , Boolean )
        at Android.Runtime.AndroidTypeManager.RegisterNativeMembers(JniType , Type , ReadOnlySpan`1 )
    --- End of stack trace from previous location ---
        at Java.Interop.JniEnvironment.StaticMethods.CallStaticObjectMethod(JniObjectReference , JniMethodInfo , JniArgumentValue* )
        at Android.Runtime.JNIEnv.FindClass(String )
        at Android.Runtime.JNIEnv.AllocObject(String )
        at Android.Runtime.JNIEnv.StartCreateInstance(String , String , JValue* )
        at Android.Runtime.JNIEnv.StartCreateInstance(String , String , JValue[] )
        at Android.Text.TextWatcherImplementor..ctor(Object , EventHandler`1 , EventHandler`1 , EventHandler`1 )
        at Android.Widget.TextView.add_TextChanged(EventHandler`1 )
        at AndroidApp1.MainActivity.OnCreate(Bundle savedInstanceState)
        at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr , IntPtr , IntPtr )
        at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V , IntPtr , IntPtr , IntPtr )
        at crc64a6e0c00971f6cd91.MainActivity.n_onCreate(Native Method)
        at crc64a6e0c00971f6cd91.MainActivity.onCreate(MainActivity.java:29)

Metadata

Metadata

Labels

Area: LinkerIssues when linking assemblies.bugComponent does not function as intended.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions