Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaProxyThrowable exceptions in Xamarin.Android #4218

Closed
leonluc-dev opened this issue Feb 4, 2020 · 4 comments
Closed

JavaProxyThrowable exceptions in Xamarin.Android #4218

leonluc-dev opened this issue Feb 4, 2020 · 4 comments

Comments

@leonluc-dev
Copy link
Contributor

In one of our apps we currently have the following code in one of our Activity classes:

protected async override void OnResume()
{
    base.OnResume();
    if (RefreshLoginOnStart)
    {     
        await RefreshLogin();
    }
}

Some of our users seem to be getting a peculiar exception however, which appears in the Google Play Console crash logs as shown below.

While according to the crash log this exception occurs in our shared code (part of a .NET standard library), it seems the final exception sent to the Android Developer Console logs is a JavaProxyThrowable with no extra information.

The exception also does not appear in our Microsoft App Center crash reporting, so it seems the App Center crash reporting library is unable to pick it up for processing.

I assume a simple try/catch would solve the issue or allow us to investigate the issue further, but I am still curious on what exactly is causing the JavaProxyThrowable to appear in the logs instead of a proper exception, and why something like App Center (which should catch all unhandled exceptions) doesn't pick it up. Does this mean the exception occurred at the Java level rather than the managed C# level?

Version Information

Microsoft Visual Studio Professional 2019
Version 16.4.2
VisualStudio.16.Release/16.4.2+29613.14
Microsoft .NET Framework
Version 4.8.03752

Installed Version: Professional

ASP.NET and Web Tools 2019   16.4.457.38025
ASP.NET and Web Tools 2019

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

Azure App Service Tools v3.0.0   16.4.457.38025
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   16.4.457.38025
Azure Functions and Web Jobs Tools

C# Tools   3.4.1-beta4-19610-02+c4e5d138903b899477649a17f197abd2bcb22f9e
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.0 (d16-2@8b56e20)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.21016.1

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.0.87+gbb515bf382
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 Studio Tools for Containers   1.1
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.

Mono Debugging for Visual Studio   16.5.24 (1fafd7e)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.4.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

SQL Server Data Tools   16.0.61912.09160
Microsoft SQL Server Data Tools

TypeScript Tools   16.0.11031.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.4.1-beta4-19610-02+c4e5d138903b899477649a17f197abd2bcb22f9e
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 10.4 for F# 4.6   16.4.0-beta.19556.5+e7597deb7042710a7142bdccabd6f92b0840d354
Microsoft Visual F# Tools 10.4 for F# 4.6

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 (Preview)   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

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.4.000.307 (d16-4@e031886)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.4.0.464 (remotes/origin/d16-4@4abf337c3)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.4.25 (579ee62)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   10.1.1.0 (d16-4/f2c9364)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: bef1e63
    Java.Interop: xamarin/java.interop/d16-4@c4e569f
    ProGuard: xamarin/proguard/master@905836d
    SQLite: xamarin/sqlite/3.28.0@46204c4
    Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b


Xamarin.iOS and Xamarin.Mac SDK   13.8.3.0 (0d8fe21)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Log File

android.runtime.JavaProxyThrowable: at TTShared.Helpers.TTLoginTask.InitNewSession (System.Threading.CancellationToken token) [0x00121] in <043cb41b1db34e27b301bb6dfce88f61>:0
at TTApp.AndroidApp.MainActivity.RefreshLogin () [0x0006d] in <56692109fe25447299cc66deaf9c0c41>:0
at TTApp.AndroidApp.MainActivity.OnResume () [0x000a6] in <56692109fe25447299cc66deaf9c0c41>:0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <c99609465e4843bd8f02ca6858441fc7>:0
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <4cef19eba4f348a4b72128580092d66d>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <4cef19eba4f348a4b72128580092d66d>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <4cef19eba4f348a4b72128580092d66d>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.58(intptr,intptr)
  at mono.java.lang.RunnableImplementor.n_run (Native Method)
  at mono.java.lang.RunnableImplementor.run (Unknown Source)
  at android.os.Handler.handleCallback (Handler.java:789)
  at android.os.Handler.dispatchMessage (Handler.java:98)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6944)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
@brendanzagaeski
Copy link
Contributor

I believe the reason the outer exception is a android.runtime.JavaProxyThrowable rather than a C# exception is that the stack trace is coming from the Google Play Console. Unhandled C# exceptions are propagated out of the managed runtime to the Android runtime (ART) via the JavaProxyThrowable type so that Android can respond to them in the normal expected ways for Java exceptions.

The problem in this case is that the information captured on the Google Play Console is missing the managed exception information that should in theory be stored in the JavaProxyThrowable.

Two initial ideas about why that information might be missing:

  • This might be a scenario where Throwable.printStackTrace() doesn't include the expected information due to Improve JavaProxyThrowable integration #1198.
  • The fact that the exception isn't showing up on App Center might mean that there is something odd about the original managed C# exception itself. It seems like the AppDomain.CurrentDomain.UnhandledException event is not getting raised as expected for the managed exception.

@jonpryor does this sound familiar at all? I searched a little to see if I could find any other cases where the string printed for the JavaProxyThrowable doesn't even include the type name of the managed exception, but I haven't found any yet.

@brendanzagaeski brendanzagaeski added this to the Under Consideration milestone Feb 6, 2020
@leonluc-dev
Copy link
Contributor Author

leonluc-dev commented Feb 7, 2020

An update on the App Center issue:

The fact that the exception isn't showing up on App Center might mean that there is something odd about the original managed C# exception itself. It seems like the AppDomain.CurrentDomain.UnhandledException event is not getting raised as expected for the managed exception.

It turns out this was related to the app process dying after the exception occurred. The App Center SDK would still register the exception and cache the report but couldn't upload the exception reports in time before the process died. And since this particular crash happened on boot it never got a chance to upload the reports in later user sessions of the app (since it would instantly die again).

When we implemented a temporary "catch-all" fix for the exceptions that would occur at app boot (so the app process wouldn't die before App Center could do its thing) all related exceptions that were cached over the last few weeks suddenly appeared in our App Center reports.

So this particular issue is unrelated to the missing information in the Google Play crash logs.

@brendanzagaeski
Copy link
Contributor

Ahh, good to know. Thanks for that additional info! Based on that new info and chatting with the team about this, I'll mark this item as a duplicate of #1198 for further tracking. I'll also chat with the team about revisiting that earlier issue to improve the crash dump information for JavaProxyThrowable in the future. Thanks again for bringing this up!

@brendanzagaeski
Copy link
Contributor

Duplicate of #1198

@brendanzagaeski brendanzagaeski marked this as a duplicate of #1198 Feb 11, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants