maui
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
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
- Run the 'dotnet new maui -n TestExceptions' command to create an app
- Replace the
OnCounterClickedmethod 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("");
}
- 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
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.
@jonathanpeppers - any thoughts on where this bug should go? VS Feedback? Or Xamarin Android repo?
@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
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.
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.