I am attempting to make a simple WinForms app with a single button that scans for and prints Bluetooth devices to the console. As soon as adapter.StartDiscoveryAsync() is called it crashes mono. I have plans to use Linux.Bluetooth at a larger scale, but not until I can get this very simple example working correctly and robustly.
Any help would be much appreciated. Let me know if you need any additional information.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Linux.Bluetooth;
using Linux.Bluetooth.Extensions;
namespace scan
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private async void button1_Click(object sender, EventArgs e)
{
int scanSeconds = 5;
IAdapter1 adapter = (await BlueZManager.GetAdaptersAsync()).FirstOrDefault();
var adapterPath = adapter.ObjectPath.ToString();
var adapterName = adapterPath.Substring(adapterPath.LastIndexOf("/") + 1);
Console.WriteLine($"Using Bluetooth adapter {adapterName}");
Console.WriteLine($"Adapter's full path: {adapterPath}");
Console.WriteLine("Starting discovery...");
await adapter.StartDiscoveryAsync();
Console.WriteLine("Delaying 5 seconds...");
await Task.Delay(TimeSpan.FromSeconds(scanSeconds));
Console.WriteLine("Stopping discovery...");
await adapter.StopDiscoveryAsync();
// Print out the devices we already know about.
Console.WriteLine();
Console.WriteLine("Getting devices...");
var devices = await adapter.GetDevicesAsync();
foreach (var device in devices)
{
string deviceDescription = await GetDeviceDescriptionAsync(device);
Console.WriteLine($" - {deviceDescription}");
}
}
private static async Task<string> GetDeviceDescriptionAsync(IDevice1 device)
{
var deviceProperties = await device.GetAllAsync();
return $"{deviceProperties.Alias} (Address: {deviceProperties.Address}, RSSI: {deviceProperties.RSSI})";
}
}
}
$ sudo ./scan.exe
Using Bluetooth adapter hci0
Adapter's full path: /org/bluez/hci0
Starting discovery...
Delaying 5 seconds...
=================================================================
Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
=================================================================
Native stacktrace:
=================================================================
(No frames)
=================================================================
Telemetry Dumper:
=================================================================
Pkilling 0x1889530880x from 0x1888478208x
Pkilling 0x1898968064x from 0x1888478208x
Pkilling 0x1985803264x from 0x1888478208x
Pkilling 0x1895822336x from 0x1888478208x
Pkilling 0x1905259520x from 0x1888478208x
Pkilling 0x1908343808x from 0x1888478208x
Pkilling 0x1892676608x from 0x1888478208x
Pkilling 0x1995820288x from 0x1888478208x
Pkilling 0x1902113792x from 0x1888478208x
Pkilling 0x1887425536x from 0x1888478208x
Entering thread summarizer pause from 0x1888478208x
Finished thread summarizer pause from 0x1888478208x.
Failed to create breadcrumb file (null)/crash_hash_0x0
Waiting for dumping threads to resume
=================================================================
External Debugger Dump:
=================================================================
[New LWP 28518]
[New LWP 28519]
[New LWP 28520]
[New LWP 28521]
[New LWP 28522]
[New LWP 28523]
[New LWP 28524]
[New LWP 28525]
[New LWP 28526]
[New LWP 28527]
[New LWP 28528]
[New LWP 28552]
Mono support loaded.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
__GI___poll (timeout=1000, nfds=2, fds=0x76203938) at ../sysdeps/unix/sysv/linux/poll.c:29
29 ../sysdeps/unix/sysv/linux/poll.c: No such file or directory.
Id Target Id Frame
* 1 Thread 0x76f5cd00 (LWP 28516) "cli" __GI___poll (timeout=1000, nfds=2, fds=0x76203938) at ../sysdeps/unix/sysv/linux/poll.c:29
2 Thread 0x75fff400 (LWP 28518) "SGen worker" futex_wait_cancelable (private=0, expected=0, futex_word=0x40d290) at ../sysdeps/nptl/futex-internal.h:186
3 Thread 0x765cf400 (LWP 28519) "Finalizer" futex_abstimed_wait_cancelable (private=0, abstime=0x0, clockid=0, expected=1, futex_word=0x405528) at ../sysdeps/nptl/futex-internal.h:323
4 Thread 0x71bf0400 (LWP 28520) "Thread Pool I/O" __GI___poll (timeout=-1, nfds=2, fds=0xbdcbd0) at ../sysdeps/unix/sysv/linux/poll.c:29
5 Thread 0x718ff400 (LWP 28521) "Thread Pool I/O" futex_abstimed_wait_cancelable (private=<optimized out>, abstime=0x718fecac, clockid=<optimized out>, expected=0, futex_word=0x40d6b8) at ../sysdeps/nptl/futex-internal.h:323
6 Thread 0x715ff400 (LWP 28522) "Thread Pool Wor" futex_abstimed_wait_cancelable (private=0, abstime=0x715fed5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
7 Thread 0x712ff400 (LWP 28523) "Thread Pool Wor" futex_abstimed_wait_cancelable (private=0, abstime=0x712fed5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
8 Thread 0x70fff400 (LWP 28524) "Thread Pool Wor" futex_abstimed_wait_cancelable (private=0, abstime=0x70ffed5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
9 Thread 0x70cff400 (LWP 28525) "Thread Pool Wor" futex_abstimed_wait_cancelable (private=0, abstime=0x70cfed5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
10 Thread 0x709ff400 (LWP 28526) "Thread Pool Wor" futex_abstimed_wait_cancelable (private=0, abstime=0x709fed5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
11 Thread 0x708fe400 (LWP 28527) "Thread Pool Wor" 0x76bb1824 in __GI___wait4 (pid=28658, stat_loc=0x708fbf54, options=0, usage=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
12 Thread 0x707fd400 (LWP 28528) "Thread Pool Wor" futex_abstimed_wait_cancelable (private=0, abstime=0x707fcd5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
13 Thread 0x6fd72400 (LWP 28552) "Timer-Scheduler" futex_abstimed_wait_cancelable (private=<optimized out>, abstime=0x6fd712d4, clockid=<optimized out>, expected=0, futex_word=0x6b1da0) at ../sysdeps/nptl/futex-internal.h:323
Thread 13 (Thread 0x6fd72400 (LWP 28552) "Timer-Scheduler"):
#0 futex_abstimed_wait_cancelable (private=<optimized out>, abstime=0x6fd712d4, clockid=<optimized out>, expected=0, futex_word=0x6b1da0) at ../sysdeps/nptl/futex-internal.h:323
#1 __pthread_cond_wait_common (abstime=0x6fd712d4, clockid=<optimized out>, mutex=0x85ed, cond=0x6b1d78) at pthread_cond_wait.c:520
#2 __pthread_cond_timedwait (cond=0x6b1d78, mutex=0x85ed, abstime=0x6fd712d4) at pthread_cond_wait.c:656
#3 0x00303b0c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 12 (Thread 0x707fd400 (LWP 28528) "Thread Pool Wor"):
#0 futex_abstimed_wait_cancelable (private=0, abstime=0x707fcd5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
#1 do_futex_wait (sem=sem@entry=0x405a88, abstime=abstime@entry=0x707fcd5c, clockid=0) at sem_waitcommon.c:117
#2 0x76e98078 in __new_sem_wait_slow (sem=0x405a88, abstime=0x707fcd5c, clockid=0) at sem_waitcommon.c:285
#3 0x002a36b0 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 11 (Thread 0x708fe400 (LWP 28527) "Thread Pool Wor"):
#0 0x76bb1824 in __GI___wait4 (pid=28658, stat_loc=0x708fbf54, options=0, usage=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
#1 0x0009d030 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 10 (Thread 0x709ff400 (LWP 28526) "Thread Pool Wor"):
#0 futex_abstimed_wait_cancelable (private=0, abstime=0x709fed5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
#1 do_futex_wait (sem=sem@entry=0x405a88, abstime=abstime@entry=0x709fed5c, clockid=0) at sem_waitcommon.c:117
#2 0x76e98078 in __new_sem_wait_slow (sem=0x405a88, abstime=0x709fed5c, clockid=0) at sem_waitcommon.c:285
#3 0x002a36b0 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 9 (Thread 0x70cff400 (LWP 28525) "Thread Pool Wor"):
#0 futex_abstimed_wait_cancelable (private=0, abstime=0x70cfed5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
#1 do_futex_wait (sem=sem@entry=0x405a88, abstime=abstime@entry=0x70cfed5c, clockid=0) at sem_waitcommon.c:117
#2 0x76e98078 in __new_sem_wait_slow (sem=0x405a88, abstime=0x70cfed5c, clockid=0) at sem_waitcommon.c:285
#3 0x002a36b0 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 8 (Thread 0x70fff400 (LWP 28524) "Thread Pool Wor"):
#0 futex_abstimed_wait_cancelable (private=0, abstime=0x70ffed5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
#1 do_futex_wait (sem=sem@entry=0x405a88, abstime=abstime@entry=0x70ffed5c, clockid=0) at sem_waitcommon.c:117
#2 0x76e98078 in __new_sem_wait_slow (sem=0x405a88, abstime=0x70ffed5c, clockid=0) at sem_waitcommon.c:285
#3 0x002a36b0 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 7 (Thread 0x712ff400 (LWP 28523) "Thread Pool Wor"):
#0 futex_abstimed_wait_cancelable (private=0, abstime=0x712fed5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
#1 do_futex_wait (sem=sem@entry=0x405a88, abstime=abstime@entry=0x712fed5c, clockid=0) at sem_waitcommon.c:117
#2 0x76e98078 in __new_sem_wait_slow (sem=0x405a88, abstime=0x712fed5c, clockid=0) at sem_waitcommon.c:285
#3 0x002a36b0 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 6 (Thread 0x715ff400 (LWP 28522) "Thread Pool Wor"):
#0 futex_abstimed_wait_cancelable (private=0, abstime=0x715fed5c, clockid=0, expected=1, futex_word=0x405a88) at ../sysdeps/nptl/futex-internal.h:323
#1 do_futex_wait (sem=sem@entry=0x405a88, abstime=abstime@entry=0x715fed5c, clockid=0) at sem_waitcommon.c:117
#2 0x76e98078 in __new_sem_wait_slow (sem=0x405a88, abstime=0x715fed5c, clockid=0) at sem_waitcommon.c:285
#3 0x002a36b0 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 5 (Thread 0x718ff400 (LWP 28521) "Thread Pool I/O"):
#0 futex_abstimed_wait_cancelable (private=<optimized out>, abstime=0x718fecac, clockid=<optimized out>, expected=0, futex_word=0x40d6b8) at ../sysdeps/nptl/futex-internal.h:323
#1 __pthread_cond_wait_common (abstime=0x718fecac, clockid=<optimized out>, mutex=0x9ddf, cond=0x40d690) at pthread_cond_wait.c:520
#2 __pthread_cond_timedwait (cond=0x40d690, mutex=0x9ddf, abstime=0x718fecac) at pthread_cond_wait.c:656
#3 0x00303b0c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 4 (Thread 0x71bf0400 (LWP 28520) "Thread Pool I/O"):
#0 __GI___poll (timeout=-1, nfds=2, fds=0xbdcbd0) at ../sysdeps/unix/sysv/linux/poll.c:29
#1 __GI___poll (fds=0xbdcbd0, nfds=2, timeout=-1) at ../sysdeps/unix/sysv/linux/poll.c:26
#2 0x002532f4 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 3 (Thread 0x765cf400 (LWP 28519) "Finalizer"):
#0 futex_abstimed_wait_cancelable (private=0, abstime=0x0, clockid=0, expected=1, futex_word=0x405528) at ../sysdeps/nptl/futex-internal.h:323
#1 do_futex_wait (sem=sem@entry=0x405528, abstime=0x0, clockid=0) at sem_waitcommon.c:117
#2 0x76e97c90 in __new_sem_wait_slow (sem=0x405528, abstime=0x0, clockid=0) at sem_waitcommon.c:285
#3 0x00292b38 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 2 (Thread 0x75fff400 (LWP 28518) "SGen worker"):
#0 futex_wait_cancelable (private=0, expected=0, futex_word=0x40d290) at ../sysdeps/nptl/futex-internal.h:186
#1 __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x0, cond=0x40d268) at pthread_cond_wait.c:508
#2 __pthread_cond_wait (cond=0x40d268, mutex=0x0) at pthread_cond_wait.c:638
#3 0x002f512c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Thread 1 (Thread 0x76f5cd00 (LWP 28516) "cli"):
#0 __GI___poll (timeout=1000, nfds=2, fds=0x76203938) at ../sysdeps/unix/sysv/linux/poll.c:29
#1 __GI___poll (fds=0x76203938, nfds=2, timeout=1000) at ../sysdeps/unix/sysv/linux/poll.c:26
#2 0x7214a778 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
[Inferior 1 (process 28516) detached]
Stopping discovery...
=================================================================
Basic Fault Address Reporting
=================================================================
instruction pointer is NULL, skip dumping
=================================================================
Managed Stacktrace:
=================================================================
=================================================================
Aborted