Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Android no stack trace in async method

Anybody maybe found some workaround for this bug:

https://bugzilla.xamarin.com/show_bug.cgi?id=30513

?

It drives me crazy... the screenshoot is the exception report I got from async method.

enter image description here

like image 625
Immons Avatar asked Oct 20 '22 06:10

Immons


2 Answers

Here is another one solution which worked for me. Just add this handler in your Application or main Activity

AndroidEnvironment.UnhandledExceptionRaiser += delegate(object sender, RaiseThrowableEventArgs args){
            typeof (System.Exception).GetField("stack_trace", BindingFlags.NonPublic | BindingFlags.Instance)
                .SetValue(args.Exception, null);
            throw args.Exception;
        };

The explanation is here in the last post https://forums.xamarin.com/discussion/45219/stack-trace-not-captured-properly

like image 148
Roman Nazarevych Avatar answered Jan 04 '23 07:01

Roman Nazarevych


Okey guys, so I have found workaround for this bug, here is step by step what to do to handle it and let Xamarin.Insights work.

  1. Add text file to Android project(name doesn't matter)and set it from "Content" in properties to "AndroidEnvironment"
  2. In the text file you created add that flag: XA_BROKEN_EXCEPTION_TRANSITIONS=true - this flag mean that we will use old, Xamarin.Android 4.x exception handling
  3. Then add android exception global handler in your droid project, it will handle Android exceptions which normally crashes application before your Xamarin.Insights(or other report tool)would be able to do some work.

AndroidEnvironment.UnhandledExceptionRaiser += (sender, args) => { args.Handled = true; }

And voila, the Xamarin.Insights is ready to work for you :)

like image 44
Immons Avatar answered Jan 04 '23 06:01

Immons