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

Throwing FooException makes AppDomain throw JavaProxyThrowable instead of FooException #1144

Closed
knocte opened this issue Dec 29, 2017 · 3 comments
Assignees
Labels
Area: App Runtime Issues in `libmonodroid.so`.

Comments

@knocte
Copy link
Contributor

knocte commented Dec 29, 2017

Steps to Reproduce

  1. Create new XamarinForms project (template from VSforMac for example).
  2. Create class FooException : Exception.
  3. Hook into AppDomain.CurrentDomain.UnhandledException with a method Bar(sender, args) that receives the exception in the args.ExceptionObject property.
  4. Make the AppPage of the app throw this new FooException.
  5. Run the app in iOS: exception received is of type FooException.
  6. Run the app in Android.

Expected Behavior

Exception received by the Bar() method is of type FooException (or at least contains the FooException in the InnerException chain?)

Actual Behavior

Exception received by the Bar() method is of type JavaProxyThrowable, and its message is "Exception of type 'Android.Runtime.JavaProxyThrowable' was thrown". The only bit of "FooException" found in this exception object is in the stack trace, however this is not an acceptable way for the callers to find what exception was really thrown, especially because it would need to be platform-specific code (only Android exhibits this behaviour, other platforms don't).

Version Information

Visual Studio Community 2017 for Mac
Version 7.3.2 (build 12)
Installation UUID: fd06ff65-69de-47ae-8b99-ddf257032b7c
Runtime:
Mono 5.4.1.7 (2017-06/e66d9abbb27) (64-bit)
GTK+ 2.24.23 (Raleigh theme)

Package version: 504010007

NuGet
Version: 4.3.1.4445

.NET Core
Runtime: /usr/local/share/dotnet/dotnet
Runtime Version: 2.0.0
SDK: /usr/local/share/dotnet/sdk/2.0.0/Sdks
SDK Version: 2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

Xamarin.Profiler
Version: 1.6.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Xamarin.Android
Version: 8.1.0.25 (Visual Studio Community)
Android SDK: /Users/andres/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
7.1 (API level 25)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 26.0.2
SDK Build Tools Version: 26.0.3

Java SDK: /usr
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Apple Developer Tools
Xcode 9.2 (13772)
Build 9C40b

Log File

(I don't believe there's need for a log file)

@jonpryor
Copy link
Member

jonpryor commented Jan 2, 2018

The problem is that we don't "unwrap" exceptions when raising the AppDomain.UnhandledException event:

var args  = new UnhandledExceptionEventArgs (ex, isTerminating: true);
AppDomain_DoUnhandledException (AppDomain.CurrentDomain, args);

ex will be a Java.Lang.Throwable instance, e.g. JavaProxyThrowable, which explains the described behavior.

@jonpryor jonpryor added the Area: App Runtime Issues in `libmonodroid.so`. label Jan 2, 2018
grendello added a commit to grendello/xamarin-android that referenced this issue Jan 3, 2018
Fixes dotnet#1144

User code cannot easily unwrap the inner exception itself unless
it uses reflection to read the `JavaProxyThrowable.InnerException`
property which is unacceptable.

Add code to unwrap the exception before calling the AppDomain
unhandled exception handler.
jonpryor pushed a commit that referenced this issue Jan 3, 2018
)

Fixes: #1144

User code cannot easily unwrap the inner exception itself unless
it uses reflection to read the `JavaProxyThrowable.InnerException`
property which is unacceptable.

Add code to unwrap the exception before calling the AppDomain
unhandled exception handler.
@knocte
Copy link
Contributor Author

knocte commented Jan 5, 2018

Wow guys that was fast! Thank you, and happy new year.

By the way, am new to XamarinAndroid, so how will I be able to get this bugfix? Through nuget or through VS4Mac update? (And is there anyway to know the version number I should be looking for...?)

Thanks!

@jonpryor
Copy link
Member

jonpryor commented Jan 5, 2018

@knocte asked:

how will I be able to get this bugfix?

That depends on whether you need a "proper" commercial installer, or if you can use just the OSS bits. The fix is only on master at present, and thus won't be released commercially until "d15-7"/Xamarin.Android 8.3. (Release date unknown.)

If you can you the OSS builds, you can follow the steps within Documentation/UsingJenkinsBuildArtifacts.md and grab one of the files from Jenkins, e.g.

jonpryor pushed a commit that referenced this issue Jan 23, 2021
Fixes: xamarin/monodroid#1147

Changes: http://github.com/xamarin/monodroid/compare/27736a7ffc48d606ab45598f761e873f8572f46a...daa2fb6ca52ecfd0884177da5b57501bb4dda3c6

  * xamarin/monodroid@daa2fb6ca: Bump to xamarin/xamarin-analysis@9524531 (#1149)
  * xamarin/monodroid@bca44d592: [tools/msbuild] <FastDeploy/> Length cannot be less than zero (#1148)
  * xamarin/monodroid@2df384fe2: [tools/msbuild] improve XA0010 error message (#1144)
  * xamarin/monodroid@b2da84d5f: [tools/msbuild] remove MSBuild targets related to the Xamarin Inspector (#1143)
@ghost ghost locked as resolved and limited conversation to collaborators Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App Runtime Issues in `libmonodroid.so`.
Projects
None yet
Development

No branches or pull requests

3 participants