maui icon indicating copy to clipboard operation
maui copied to clipboard

An Android app crashes or hangs when I try to obtain a StackTrace after calling a method via reflection in try/catch block

Open nevse opened this issue 3 years ago • 1 comments

Description

I use the following buttonclick handler to test my app

void OnCounterClicked(object sender, EventArgs e)
{        
    try {
        MethodInfo method = typeof(MainPage).GetMethod("Test");
        method.Invoke(this, null);
    }
    catch {
    }        
    CounterBtn.Text = Environment.StackTrace;
}
public void Test() 
{        
        throw new Exception("");
}

When I try to call Environment.StackTrace to obtain a stack trace, the app hangs or crashes without any information.

Steps to Reproduce

  1. Run the 'dotnet new maui -n TestExceptions' command to create an app
  2. Replace the OnCounterClicked method with my custom method:
void OnCounterClicked(object sender, EventArgs e)
{        
    try {
        MethodInfo method = typeof(MainPage).GetMethod("Test");
        method.Invoke(this, null);
    }
    catch {
    }        
    CounterBtn.Text = Environment.StackTrace;
}
public void Test() 
{        
        throw new Exception("");
}
  1. Run the app on the android and click the button.

ps. if you try to debug the code on the line CounterBtn.Text = Environment.StackTrace;, the debugger will detach from this app and the app crashes or hangs.

Link to public reproduction project repository

https://github.com/nevse/maui-tests-reflection-vs-exception

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

android 11

Did you find any workaround?

No I didn't

Relevant log output

No response

nevse avatar Sep 20 '22 05:09 nevse

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Sep 21 '22 18:09 ghost

@jonathanpeppers - any thoughts on where this bug should go? VS Feedback? Or Xamarin Android repo?

Eilon avatar Sep 26 '22 20:09 Eilon

@nevse I'm not seeing an issue running the sample app and placing breakpoints, but maybe I'm doing something wrong?

If the app crashes for you with the latest stable VS/MAUI, we need a log from adb logcat to know where the problem is.

Can you set a system property to enable more logging:

adb shell setprop debug.mono.log default,assembly,mono_log_level=debug,mono_log_mask=all

Then cause the crash, and save the log via adb logcat -d > log.txt and share it here. Thanks!

More details here: https://learn.microsoft.com/xamarin/android/deploy-test/debugging/android-debug-log#accessing-from-the-command-line

jonathanpeppers avatar Sep 27 '22 13:09 jonathanpeppers

Hi @nevse. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Sep 27 '22 13:09 ghost

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

ghost avatar Oct 03 '22 00:10 ghost