android: Link assemblies causes app crashes if you have an EditText in VS2019 Preview 2

Steps to Reproduce

  1. Add an EditText
  2. Choose TextChanged. (Example: txtSearch.TextChanged += TxtSearch_TextChanged;)
  3. Choose Linking with either “Sdk Assemblies Only” or “Sdk and User Assemblies”.
  4. Execute the program.

Expected Behavior

Be able to execute the TextChanged on Linking with either “Sdk Assemblies Only” or “Sdk and User Assemblies”.

Actual Behavior

App crashes because it cannot load ITextWatcherInvoker.

Version Information

Windows 10, May Update. Visual Studio 2019 Preview 2.

Log File

System.TypeLoadException: ‘Could not load type ‘Android.Text.ITextWatcherInvoker’ from assembly ‘Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’.’

Annotation 2019-06-20 003519

P.S.

It’s working in Visual Studio for Mac.

VS bug #947890

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 9
  • Comments: 22 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Correcting my previous comment. Thanks MichaelBourkeCF!

Workaround notes for “System.TypeLoadException: 'Could not load type ‘Android.Text.ITextWatcherInvoker’ from assembly 'Mono.Android”

In case any other users come across this issue when using Xamarin.Android 9.4, a possible workaround is to use a custom linker configuration to preserve the missing types. To do that, add a new linker.xml file to the project, set the Build Action to LinkDescription, and add the XML lines to preserve the missing types. For example, for the ITextWatcherInvoker error, add the following lines to the file:

<linker>
  <assembly fullname="Mono.Android">
    <type fullname="Android.Text.ITextWatcherInvoker" preserve="all" />
  </assembly>
</linker>

(Note: This workaround is for the symptom described at the beginning of this issue.)

I have exactly the same error however I’m using 16.2.0 Preview 3. I’m going to try an reproduce in a test project

Thanks for the fix. However, it seems that now there is no linking done at all. My build now produces a much larger APK output, regardless of whether I select link SDK or link None. Is this the expected behaviour?

I have rolled back to xamarin.android 9.2.3-0 to bypass this issue. 9.2.3-0 is the most stable version from recent ones imho. Rolling back is easy. If you already have an old version on your system just change the “Current” symlink in /Library/Frameworks/Xamarin.Android.framework/Versions. If don’t, then just download it first.

I have the same error in Visual Studio Community 2019 16.2.0.

Workaround notes for “System.TypeLoadException: 'Could not load type ‘Android.Text.ITextWatcherInvoker’ from assembly 'Mono.Android”

In case any other users come across this issue when using Xamarin.Android 9.4, a possible workaround is to use a custom linker configuration to preserve the missing types. To do that, add a new linker.xml file to the project, set the Build Action to LinkDescription, and add the XML lines to preserve the missing types. For example, for the ITextWatcherInvoker error, add the following lines to the file:

<linker>
  <assembly fullname="Xamarin.Android">
    <type fullname="Android.Text.ITextWatcherInvoker" preserve="all" />
  </assembly>
</linker>

(Note: This workaround is for the symptom described at the beginning of this issue.)

Hi, this should be “Mono.Android” rather than “Xamarin.Android” in the xml file. It won’t compile otherwise.

Size of my apk has increased from 26mb to 31mb after the update.

I’ve got a repro in https://github.com/xamarin/monodroid-samples/blob/master/android5.0/Topeka/Topeka/Fragments/SignInFragment.cs#L90, just build and deploy the app in release mode and it’ll crash on startup.

The Issue expanded to the latest version of Visual Studio for Mac.

Windows fix published. The new Xamarin.Android SDK version 9.4.1.0 that includes a fix for this issue has now been published as part of Visual Studio 2019 version 16.2.1. Check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/ to get the fix.

macOS fix published. The new Xamarin.Android SDK version 9.4.1.0 that includes a fix for this issue has now been released in the Stable updater channel in Visual Studio for Mac. Check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/ to get the fix.

Workaround notes for “System.TypeLoadException: 'Could not load type ‘Android.Text.ITextWatcherInvoker’ from assembly 'Mono.Android”

In case any other users come across this issue when using Xamarin.Android 9.4, a possible workaround is to use a custom linker configuration to preserve the missing types. To do that, add a new linker.xml file to the project, set the Build Action to LinkDescription, and add the XML lines to preserve the missing types. For example, for the ITextWatcherInvoker error, add the following lines to the file:

<linker>
  <assembly fullname="Xamarin.Android">
    <type fullname="Android.Text.ITextWatcherInvoker" preserve="all" />
  </assembly>
</linker>

(Note: This workaround is for the symptom described at the beginning of this issue.)

Don’t know about the release version yet. I can reproduce the issue locally and I am looking into it.

I’ve got a repro in https://github.com/xamarin/monodroid-samples/blob/master/android5.0/Topeka/Topeka/Fragments/SignInFragment.cs#L90, just build and deploy the app in release mode and it’ll crash on startup.