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

Created on 20 Jun 2019  路  22Comments  路  Source: xamarin/xamarin-android

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

App Runtime bug regression vs-sync

Most helpful comment

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.)

All 22 comments

Thanks for the report! I assume you're referring to VS 2019 16.2 Preview 2? Could you paste the information displayed in Help -> About Microsoft Visual Studio? I was unable to reproduce this with the upcoming VS 2019 16.2 Preview 3 release, though my repro may not have been sufficient. Could you also attach a solution file that demonstrates this crash?

Thanks for the report! I assume you're referring to VS 2019 16.2 Preview 2? Could you paste the information displayed in Help -> About Microsoft Visual Studio? I was unable to reproduce this with the upcoming VS 2019 16.2 Preview 3 release, though my repro may not have been sufficient. Could you also attach a solution file that demonstrates this crash?

Yes, it's in the Preview 2 of VS 2019 for Windows only, I could try maybe sharing a OneDrive link because the solution is somehow huge more than a 100Mb.

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

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.

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.

Hi @radekdoulik , do we have any news in which release is going to be a fix about this issue? Preview 5? Or Later? Thanks.

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

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

I have a similar issue with CoordinatorLayouts, should I share the request here too?

@FANMixco asked:

I have a similar issue with CoordinatorLayouts, should I share the request here too?

Please do. Is it an TypeLoadException with the same ITextWatcherInvoker type, or is it a different exception or missing type?

Are you able to use any of the recent d16-3 or master builds to see if that fixes things for you?

Thanks,

  • Jon

@FANMixco asked:

I have a similar issue with CoordinatorLayouts, should I share the request here too?

Please do. Is it an TypeLoadException with the same ITextWatcherInvoker type, or is it a different exception or missing type?

Are you able to use any of the _recent_ d16-3 or master builds to see if that fixes things for you?

Thanks,

  • Jon

I'm going to check during the week, also, here is the new bug:

https://github.com/xamarin/xamarin-android/issues/3376

The Topeka repro mentioned above is now working for me with the latest d16-3 build.

I was unable to reproduce the issue mentioned in #3376 in both 16.1 and 16.3 just by quickly modifying a new template, so I think we'll want to follow up on that issue separately. If you could attach logcat output and/or a project which reproduces the crash to the new issue you've filed that would be very helpful!

The Topeka repro mentioned above is now working for me with the latest d16-3 build.

I was unable to reproduce the issue mentioned in #3376 in both 16.1 and 16.3 just by quickly modifying a new template, so I think we'll want to follow up on that issue separately. If you could attach logcat output and/or a project which reproduces the crash to the new issue you've filed that would be very helpful!

Hi, here it is:

https://drive.google.com/open?id=1uBO5Xs2F83WZJA_pGxc5oYHN5PuJ6XSg

Also, I have another project where in Debug and Release behaves differently. In Release it misses the back button from a Search Bar and if you compress it then crashes when you run it:

https://drive.google.com/open?id=1O_IyVYcMmue5Tcm4z7REG5K20ILWseZS

Both of them use the same control for the search (https://www.nuget.org/packages/Xamarin-MaterialSearchBar/), but in one in Release without Linking works properly (TipSal) and the second with Linking, but no compressing it works differently (no back button when you try searching something).
Thanks for your support.

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.)

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.

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 the same error in Visual Studio Community 2019 16.2.0.

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.

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.

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?

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

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.

Hi @brendanzagaeski any idea about the previous issues? Because it seems the issue is a new one then.

Thanks for the heads-up! I looked through the open issues, noticed a similar report in https://github.com/xamarin/xamarin-android/issues/3454, and was able to confirm the problematic linker behavior using a new blank app project as suggested in that issue.

The size increase problem can now be tracked in that issue: https://github.com/xamarin/xamarin-android/issues/3454.

I'll keep an eye on that issue to make sure the status stays updated to reflect the investigation and release.

Was this page helpful?
0 / 5 - 0 ratings