Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] [Android] TargetInvocationException for Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer with Xamarin.Forms 5.0 #14738

Closed
avorobjovs opened this issue Oct 15, 2021 · 4 comments · Fixed by #14748
Labels
i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/Android s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. s/unverified New report that has yet to be verified t/bug 🐛

Comments

@avorobjovs
Copy link

avorobjovs commented Oct 15, 2021

Description

We have a lot of issues in the production on many different Android devices (with different OS versions) after updating Xamarin.Forms to version 5.0. The System.Reflection.TargetInvocationException is thrown periodically for the Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer on different pages.

With Xamarin.Forms version 5.0.0.2083 we had this stack trace:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <9a7b03645b924be39a25109c77e8d2c9>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <9a7b03645b924be39a25109c77e8d2c9>:0 
  at Android.Views.View.get_LayoutParameters () [0x0000a] in <d60fae3f74e947019f32e4577671f7c1>:0 
  at Xamarin.Forms.Platform.Android.ButtonLayoutManager.UpdateTextAndImage () [0x00030] in <0021cb9418d04f5eb438044035483554>:0 
  at Xamarin.Forms.Platform.Android.ButtonLayoutManager.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00083] in <0021cb9418d04f5eb438044035483554>:0 
...

Full stack trace is in the attachment:
TargetInvocationException_FastRenderers.ButtonRenderer_Xamarin.Forms_5.0.0.2083.txt

After updating Xamarin.Forms to version 5.0.0.2125 we have slightly different stack trace:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <1959115d56f8444789986cf39185638c>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <1959115d56f8444789986cf39185638c>:0 
  at Android.Views.View.set_Enabled (System.Boolean value) [0x00022] in <fb24f5518a9b4a54850cdd0dc561edd9>:0 
  at Xamarin.Forms.Platform.Android.FastRenderers.VisualElementRenderer.UpdateIsEnabled () [0x00022] in <e67d82e0506f4cd0a9edc61833a79ad5>:0 
  at Xamarin.Forms.Platform.Android.FastRenderers.VisualElementRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00035] in <e67d82e0506f4cd0a9edc61833a79ad5>:0 
...

Full stack trace is in the attachment:
TargetInvocationException_FastRenderers.ButtonRenderer_Xamarin.Forms_5.0.0.2125.txt

Basic Information

  • Version with issue: 5.0.0.2083, 5.0.0.2125
  • Last known good version: 4.4.0.991864
  • Platform Target Frameworks:
    • Android: many different versions
  • Affected Devices: many different devices

Environment

Show/Hide Visual Studio info
Microsoft Visual Studio Enterprise 2019
Version 16.11.5
VisualStudio.16.Release/16.11.5+31729.503
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Enterprise

Architecture Diagrams and Analysis Tools   00435-60000-00000-AA972
Microsoft Architecture Diagrams and Analysis Tools

Visual C++ 2019   00435-60000-00000-AA972
Microsoft Visual C++ 2019

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools 2019   16.11.75.64347
ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2012   16.11.75.64347
For additional information, visit https://www.asp.net/

ASP.NET Web Frameworks and Tools 2019   16.11.75.64347
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.11.75.64347
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.6.1000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   16.11.75.64347
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.1000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   3.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

GitHub.VisualStudio   2.11.106.19330
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure HDInsight Azure Node   2.6.1000.0
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service   2.6.1000.0
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio   16.10
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service   2.6.1000.0
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.1.113+g422d40002e.RR
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.2
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   16.10.15 (552afdf)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.11.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Razor (ASP.NET Core)   16.1.0.2122504+13c05c96ea6bdbe550bd88b0bf6cdddf8cde1725
Provides languages services for ASP.NET Core Razor.

Snapshot Debugging Extension   1.0
Snapshot Debugging Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.62107.28140
Microsoft SQL Server Data Tools

SQL Server Reporting Services   15.0.19528.0
Microsoft SQL Server Reporting Services Designers 
Version 15.0.19528.0

tangible T4 Editor   2.5.0
tangible engineering GmbH

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   16.0.30526.2002
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   16.11.0-beta.21322.6+488cc578cafcd261d90d748d8aaa7b8b091232dc
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

Visual Studio Tools for Kubernetes   1.0
Visual Studio Tools for Kubernetes

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.11.000.190 (d16-11@2391ed9)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.11.0.17 (remotes/origin/11e0001f0b17269345e80b58fb3adf1ba4efe2cd@11e0001f0)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.10.5 (355b57a)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.4.0.5 (d16-11/7776c9f)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: c633fe9
    Java.Interop: xamarin/java.interop/d16-11@48766c0
    ProGuard: Guardsquare/proguard/v7.0.1@912d149
    SQLite: xamarin/sqlite/3.35.4@85460d3
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-11@683f375


Xamarin.iOS and Xamarin.Mac SDK   15.0.0.8 (0796d78dc)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
@avorobjovs avorobjovs added s/unverified New report that has yet to be verified t/bug 🐛 labels Oct 15, 2021
@jfversluis
Copy link
Member

Hey there! Thanks for the report.

Are you able to pinpoint a more exact source of error in your code? It seems like you're getting this through a error reporting service you have implemented, but it would greatly help us if you could provide a reproduction or at least some code that is associated with what we're seeing here.

@avorobjovs
Copy link
Author

Hi,

Unfortunately, I cannot. It happens randomly on different pages on different devices. Yes, we get this through the error reporting service that we have implemented. Most of the errors I see in this reporting service are from our users' devices. But today I was able to see it on my device. And it happened just when I opened a page. And I don't know why and what is the reason. And I cannot reproduce it at will.

@jsuarezruiz jsuarezruiz added the i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often label Oct 18, 2021
@jsuarezruiz jsuarezruiz added s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Oct 18, 2021
@jfversluis
Copy link
Member

@avorobjovs, a PR (#14748) for this is open now, would you be able to grab the NuGet as described here, make really sure you get the specific version for this PR, and let us know if this fixes this issue? That will greatly speed up the review process. I think it's tough because you only see it in production? And I wouldn't recommend using this in production, but let us know if you can do anything with this 😅

Besides verifying if this particular issue is fixed also be sure to check other scenarios in the same area to make sure that this fix doesn't accidentally has side-effects 🙂

Thanks!

@avorobjovs
Copy link
Author

avorobjovs commented Oct 22, 2021

@jfversluis

I tried to reproduce this issue on my devices, but I cannot do this at will. It happens seldom and spontaneously.

Then I updated Xamarin.Forms to version 5.0.0.7716+0-pr.14748-sha.efb976c25-azdo.48284, if I understood it correctly and tried to test again. And again I had no issues.

But I checked your changes in code and I think it can fix this issue. Additionally, I would suggest making the same changes also in the Xamarin.Forms.Platform.Android.ButtonLayoutManager class according to the first stack trace from my bug report.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/Android s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants