Repository navigation
Closed
Labels
Area: Mono RuntimeMono-related issues: BCL bugs, AOT issues, etc.need-attentionA xamarin-android contributor needs to review
Description
Android application type
.NET Android (net7.0-android, net8.0-android, etc.)
Affected platform version
.NET 8.0.101
Description
Application does not catch exception after running a System.Diagnostics.Process in release mode, in debug mode it runs fine.
Note that it does not cause a crash on every exception for example if you throw new Exception(), this won't result in a crash in release mode.
Steps to Reproduce
Use the default Android Application template and add the following code:
using System.Diagnostics;
using System.Xml;
using _Microsoft.Android.Resource.Designer;
using Android.Util;
using Activity = Android.App.Activity;
namespace AndroidApp1;
[Activity(Label = "@string/app_name", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(ResourceConstant.Layout.activity_main);
CatchException("Before ShellCommand");
using var _ = Process.Start(new ProcessStartInfo("/system/bin/hostname"));
CatchException("After ShellCommand"); // this will crash the application in release mode
}
private static void CatchException(string name)
{
const string tag = "net8_Crash";
Log.Warn(tag, name);
try
{
XmlAttributeCollection? attributes = null;
_ = attributes!["foo"];
}
catch (Exception e)
{
Log.Error(tag, $"EXCEPTION {e}");
}
}
}Observe that when the app is started in debug mode the application runs fine but in release mode it crashes.
Did you find any workaround?
Find another way to do what you want to do without using a Process.
Relevant log output
2024-01-18 12:58:27.897 299-299 gralloc pid-299 I gralloc_unregister_buffer hnd=0xb433e080, share_fd=85, share_attr_fd=96, magic=51647890, format=1, internal_format=1, byte_stride=2880, flags=4, usage=0xb00, size=138240, width=720, height=48, internalWidth=720, internalHeight=48, stride=720, base=0xb57c1000, writeOwner=0, attr_base=0xffffffff, yuv_info=1, fd=-1, buf_idx=0, offset=0, min_pgsz=4096, phyaddr=0
2024-01-18 12:58:28.002 866-866 StatusBar pid-866 D onColorsChanged_2:flag = 1
2024-01-18 12:58:28.002 866-866 StatusBar pid-866 D onColorsChanged_2:darkTextInKeyguard?false
2024-01-18 12:58:28.003 866-866 SystemUI.N...nPanelView pid-866 D applyKeyguardTextColor:darkText?false
2024-01-18 12:58:28.003 866-866 KeyguardAffordanceView pid-866 D updateIconColor:color=-1
2024-01-18 12:58:28.003 866-866 KeyguardAffordanceView pid-866 D updateIconColor:color=-1
2024-01-18 12:58:28.003 866-866 LockIcon pid-866 D updateIconColor:color=-1
2024-01-18 12:58:28.003 866-866 StatusBar pid-866 D applyKeyguardTextColor
2024-01-18 12:58:28.003 866-866 StatusBar pid-866 D mKeyguardCarrierLabel.getChildCount() = 2
2024-01-18 12:58:28.008 617-617 CheckTime pid-617 W App running slow: Executing handleBindApplication : installContentProviders took 364ms
2024-01-18 12:58:28.015 277-277 gralloc pid-277 I gralloc_unregister_buffer hnd=0xa7937b00, share_fd=62, share_attr_fd=67, magic=51647890, format=1, internal_format=1, byte_stride=2880, flags=4, usage=0xb00, size=4147200, width=720, height=1440, internalWidth=720, internalHeight=1440, stride=720, base=0xa122b000, writeOwner=0, attr_base=0xffffffff, yuv_info=1, fd=-1, buf_idx=0, offset=0, min_pgsz=4096, phyaddr=0
2024-01-18 12:58:28.015 277-277 gralloc pid-277 I gralloc_unregister_buffer hnd=0xa7937bc0, share_fd=76, share_attr_fd=78, magic=51647890, format=1, internal_format=1, byte_stride=2880, flags=4, usage=0xb00, size=4147200, width=720, height=1440, internalWidth=720, internalHeight=1440, stride=720, base=0xa0e36000, writeOwner=0, attr_base=0xffffffff, yuv_info=1, fd=-1, buf_idx=0, offset=0, min_pgsz=4096, phyaddr=0
2024-01-18 12:58:28.015 277-277 gralloc pid-277 I gralloc_unregister_buffer hnd=0xa7936b40, share_fd=68, share_attr_fd=72, magic=51647890, format=1, internal_format=1, byte_stride=2880, flags=4, usage=0xb00, size=4147200, width=720, height=1440, internalWidth=720, internalHeight=1440, stride=720, base=0xa3c0b000, writeOwner=0, attr_base=0xffffffff, yuv_info=1, fd=-1, buf_idx=0, offset=0, min_pgsz=4096, phyaddr=0
2024-01-18 12:58:28.015 299-299 gralloc pid-299 I gralloc_unregister_buffer hnd=0xb433e800, share_fd=79, share_attr_fd=89, magic=51647890, format=1, internal_format=1, byte_stride=2880, flags=4, usage=0xb00, size=4147200, width=720, height=1440, internalWidth=720, internalHeight=1440, stride=720, base=0xad88d000, writeOwner=0, attr_base=0xffffffff, yuv_info=1, fd=-1, buf_idx=0, offset=0, min_pgsz=4096, phyaddr=0
2024-01-18 12:58:28.016 299-299 gralloc pid-299 I gralloc_unregister_buffer hnd=0xb433d900, share_fd=59, share_attr_fd=80, magic=51647890, format=1, internal_format=1, byte_stride=2880, flags=4, usage=0xb00, size=4147200, width=720, height=1440, internalWidth=720, internalHeight=1440, stride=720, base=0xaf78b000, writeOwner=0, attr_base=0xffffffff, yuv_info=1, fd=-1, buf_idx=0, offset=0, min_pgsz=4096, phyaddr=0
2024-01-18 12:58:28.151 617-617 net8_Crash pid-617 W Before ShellCommand
2024-01-18 12:58:28.215 277-277 gralloc pid-277 I gralloc_unregister_buffer hnd=0xa7937800, share_fd=64, share_attr_fd=65, magic=51647890, format=2, internal_format=2, byte_stride=6720, flags=4, usage=0x933, size=9676800, width=1680, height=1440, internalWidth=1680, internalHeight=1440, stride=1680, base=0xa31d3000, writeOwner=0, attr_base=0xffffffff, yuv_info=1, fd=-1, buf_idx=0, offset=0, min_pgsz=4096, phyaddr=0
2024-01-18 12:58:28.221 617-617 net8_Crash pid-617 E EXCEPTION System.NullReferenceException: Object reference not set to an instance of an object
at AndroidApp1.MainActivity.CatchException(String name)
2024-01-18 12:58:28.444 617-617 net8_Crash pid-617 W After ShellCommand
2024-01-18 12:58:28.444 617-617 libsigchain pid-617 E exiting due to SIG_DFL handler for signal 11
2024-01-18 12:58:28.445 617-617 libc pid-617 A Fatal signal 6 (SIGABRT), code -6 in tid 617 (ame.AndroidApp1), pid 617 (ame.AndroidApp1)
2024-01-18 12:58:28.537 638-638 crash_dump32 pid-638 I obtaining output fd from tombstoned, type: kDebuggerdTombstone
2024-01-18 12:58:28.538 470-470 /system/bin/tombstoned pid-470 I received crash request for pid 617
2024-01-18 12:58:28.539 638-638 crash_dump32 pid-638 I performing dump of process 617 (target tid = 617)
2024-01-18 12:58:28.539 638-638 DEBUG pid-638 A *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2024-01-18 12:58:28.539 638-638 DEBUG pid-638 A Native Crash TIME: 112261690
2024-01-18 12:58:28.539 638-638 DEBUG pid-638 A *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2024-01-18 12:58:28.539 638-638 DEBUG pid-638 A Build fingerprint: 'PAX/A50/A50:8.1.0/OPM2.171019.012/6:user/release-keys'
2024-01-18 12:58:28.540 638-638 DEBUG pid-638 A Revision: '0'
2024-01-18 12:58:28.540 638-638 DEBUG pid-638 A ABI: 'arm'
2024-01-18 12:58:28.540 638-638 DEBUG pid-638 A pid: 617, tid: 617, name: ame.AndroidApp1 >>> com.companyname.AndroidApp1 <<<
2024-01-18 12:58:28.540 638-638 DEBUG pid-638 A signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
2024-01-18 12:58:28.540 638-638 DEBUG pid-638 A r0 00000000 r1 00000269 r2 00000006 r3 00000008
2024-01-18 12:58:28.540 638-638 DEBUG pid-638 A r4 00000269 r5 00000269 r6 abd85c34 r7 0000010c
2024-01-18 12:58:28.540 638-638 DEBUG pid-638 A r8 00000000 r9 abd85c90 sl 0000000b fp 00000000
2024-01-18 12:58:28.540 638-638 DEBUG pid-638 A ip abd85c64 sp abd85c20 lr aa9acc1b pc aa9a6734 cpsr 20000030
2024-01-18 12:58:28.546 638-638 DEBUG pid-638 A
backtrace:
2024-01-18 12:58:28.546 638-638 DEBUG pid-638 A #00 pc 00019734 /system/lib/libc.so (abort+63)
2024-01-18 12:58:28.546 638-638 DEBUG pid-638 A #01 pc 00002441 /system/bin/app_process32 (art::SignalChain::Handler(int, siginfo*, void*)+736)
2024-01-18 12:58:28.546 638-638 DEBUG pid-638 A #02 pc 0001922c /system/lib/libc.so
2024-01-18 12:58:28.546 638-638 DEBUG pid-638 A #03 pc 000004ac /data/app/com.companyname.AndroidApp1-b4nVVJh7NPmbCugJKx_nug==/split_config.armeabi_v7a.apk (offset 0xd2000)
2024-01-18 12:58:28.769 663-663 SprdLightsUtils pid-663 D id = 4; isBatteryLightOpen = true
2024-01-18 12:58:29.213 470-470 /system/bin/tombstoned pid-470 E Tombstone written to: /data/tombstones/tombstone_01
2024-01-18 12:58:29.215 663-639 ActivityManager pid-663 W Force finishing activity com.companyname.AndroidApp1/crc64a6e0c00971f6cd91.MainActivity
2024-01-18 12:58:29.218 663-682 BootReceiver pid-663 I Copying /data/tombstones/tombstone_01 to DropBox (SYSTEM_TOMBSTONE)
2024-01-18 12:58:29.223 663-1033 PowerContr...r.AppState pid-663 D - reportAppStateEventInfo() E -
2024-01-18 12:58:29.223 663-1036 PowerController.RecogA pid-663 D handleMessage(MSG_REPORT_EVENT)
2024-01-18 12:58:29.234 663-678 ActivityManager pid-663 I Showing crash dialog for package com.companyname.AndroidApp1 u0
2024-01-18 12:58:29.260 277-277 gralloc pid-277 I gralloc_unregister_buffer hnd=0xa79378c0, share_fd=56, share_attr_fd=61, magic=51647890, format=1, internal_format=1, byte_stride=2880, flags=4, usage=0x933, size=4147200, width=720, height=1440, internalWidth=720, internalHeight=1440, stride=720, base=0xa2dde000, writeOwner=0, attr_base=0xffffffff, yuv_info=1, fd=-1, buf_idx=0, offset=0, min_pgsz=4096, phyaddr=0
2024-01-18 12:58:29.264 663-678 WindowManager pid-663 D Input focus has changed to Window{70a4b4a u0 Application Error: com.companyname.AndroidApp1}
2024-01-18 12:58:29.269 663-3928 ActivityManager pid-663 W Process com.companyname.AndroidApp1 (pid 617) has died: fore TOP
2024-01-18 12:58:29.270 663-679 zygote pid-663 W kill(-617, 9) failed: No such process
2024-01-18 12:58:29.270 663-679 zygote pid-663 I Successfully killed process cgroup uid 10232 pid 617 in 0ms
2024-01-18 12:58:29.270 443-443 Zygote pid-443 I Process 617 exited due to signal (6)
2024-01-18 12:58:29.274 663-778 gralloc pid-663 I gralloc_unregister_buffer hnd=0x8c3aed40, share_fd=256, share_attr_fd=324, magic=51647890, format=1, internal_format=1, byte_stride=2880, flags=4, usage=0x933, size=4147200, width=720, height=1440, internalWidth=720, internalHeight=1440, stride=720, base=0x7d635000, writeOwner=48, attr_base=0xffffffff, yuv_info=1, fd=-1, buf_idx=0, offset=0, min_pgsz=4096, phyaddr=0
2024-01-18 12:58:29.275 299-299 gralloc pid-299 I gralloc_unregister_buffer hnd=0xb433de40, share_fd=93, share_attr_fd=101, magic=51647890, format=1, internal_format=1, byte_stride=2880, flags=4, usage=0x933, size=4147200, width=720, height=1440, internalWidth=720, internalHeight=1440, stride=720, base=0xae88b000, writeOwner=0, attr_base=0xffffffff, yuv_info=1, fd=-1, buf_idx=0, offset=0, min_pgsz=4096, phyaddr=0
2024-01-18 12:58:29.280 663-778 WindowManager pid-663 W Failed looking up window callers=com.android.server.wm.WindowManagerService.windowForClientLocked:5850 com.android.server.wm.WindowManagerService.removeWindow:1740 com.android.server.wm.Session.remove:222
2024-01-18 12:58:29.289 663-1033 PowerContr...r.AppState pid-663 D - reportAppStateEventInfo() E -Metadata
Metadata
Assignees
Labels
Area: Mono RuntimeMono-related issues: BCL bugs, AOT issues, etc.need-attentionA xamarin-android contributor needs to review
Activity
grendello commentedon Jan 18, 2024
@Procee Does the issue happen when you do not call
S.D.Process.Start()and throw aNullReferenceException()instead? And, what is the device you're running this on? I can see it' a 32-bit arm emulator or device, is it by chance a Samsung one? Also, does the crash happen also on 64-bit devices?Procee commentedon Jan 18, 2024
I've tested it on a PAX A77 that's the logcat you've seen. I also tested it on a Pixel 3A 64bit emulator and a Samsung A52A. They all behave the same.
If I throw a NullReferenceException manually the application does not crash. And if I don't start the Process the application does not crash either.
simonrozsival commentedon Jan 19, 2024
I can reproduce the issue directly in .NET without the dependency on Xamarin. I created a new issue in the
dotnet/runtimerepo and I think we can close this issue in favor of the new one, @grendello.@grendello I noticed that the runtime sample app crashes even in Debug mode unless I turn on interpreter. Is Xamarin using interpreter in Debug?
grendello commentedon Jan 19, 2024
@simonrozsival yep, Debug uses the interpreter by default (for hot reload)
grendello commentedon Jan 19, 2024
@Procee The issue is now tracked at dotnet/runtime#97209 and I'm going to close this one to avoid confusion.