SIGABRT: Failed to marshal the Objective-C object 0x282cce680 (type: CoreBluetooth_CBPeripheral__CBPeripheralDelegate). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'CoreBluetooth.CBPeripheral+_CBPeripheralDelegate' does not have a constructor that takes one IntPtr argument). #19579
Description
We have an app in production that reads BLE ad packets, and it has been running fine for the past year until iOS 17 came out, and now we are getting this crash:
SIGABRT: Failed to marshal the Objective-C object 0x282cce680 (type: CoreBluetooth_CBPeripheral__CBPeripheralDelegate). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'CoreBluetooth.CBPeripheral+_CBPeripheralDelegate' does not have a constructor that takes one IntPtr argument).
Stack Trace
Runtime.MissingCtor (System.IntPtr ptr, System.IntPtr klass, System.Type type, ObjCRuntime.Runtime+MissingCtorResolution resolution)
Runtime.ConstructNSObject[T] (System.IntPtr ptr, System.Type type, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution)
Runtime.ConstructNSObject (System.IntPtr ptr, System.IntPtr klass, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution)
Runtime.GetNSObject (System.IntPtr ptr, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution, System.Boolean evenInFinalizerQueue)
Runtime.GetNSObject (System.IntPtr ptr)
CBPeripheral.get_WeakDelegate ()
CBPeripheral.EnsureCBPeripheralDelegate ()
CBPeripheral.remove_DiscoveredService (System.EventHandler`1[TEventArgs] value)
Plugin.Bluetooth.Device..ctor (CoreBluetooth.CBPeripheral peripheral) <0x106e5e770 + 0x00153> in <a820575b929f4a13bfbda461a7222989#05679fad2e06f8641a6c40ed4f50ad68>:0
BluetoothScanner.OnDiscoveredPeripheral (System.Object sender, CoreBluetooth.CBDiscoveredPeripheralEventArgs eventArgs)
CBCentralManager+_CBCentralManagerDelegate.DiscoveredPeripheral (CoreBluetooth.CBCentralManager central, CoreBluetooth.CBPeripheral peripheral, Foundation.NSDictionary advertisementData, Foundation.NSNumber RSSI)
(wrapper managed-to-native) UIKit.UIApplication.xamarin_UIApplicationMain(int,intptr,intptr,intptr,intptr&)
UIApplication.UIApplicationMain (System.Int32 argc, System.String[] argv, System.IntPtr principalClassName, System.IntPtr delegateClassName)
UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass)
Application.Main (System.String[] args)
Steps to Reproduce
- Run an app using bluetooth api on iOS 17 in a high volume environment
Expected Behavior
Processing of BLE advertisements with no crashing
Actual Behavior
Random crashing after a few seconds of running the application (only happening on iOS 17)
Environment
Xcode 15.0.1 (also tried Xcode 15.1)
iOS 17 (and all subsequent versions)
Version information
Visual Studio Community 2022 for Mac
Version 17.6.7 (build 417)
Installation UUID: 297f9b93-4d59-458a-882b-6528b4fdd966
Runtime
.NET 7.0.3 (64-bit)
Architecture: Arm64
Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2
Roslyn (Language Service)
4.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa
NuGet
Version: 6.4.0.117
.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/7.0.311/Sdks
SDK Versions:
7.0.311
7.0.310
7.0.309
7.0.308
7.0.307
7.0.306
7.0.304
7.0.302
7.0.203
7.0.202
7.0.201
7.0.200
7.0.102
7.0.101
7.0.100
6.0.417
6.0.416
6.0.415
6.0.414
6.0.413
6.0.412
6.0.410
6.0.408
6.0.407
6.0.406
6.0.405
6.0.404
6.0.403
6.0.401
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks
.NET SDK (x64)
SDK Versions:
3.1.426
3.1.425
3.1.423
.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
7.0.14
7.0.13
7.0.12
7.0.11
7.0.10
7.0.9
6.0.25
6.0.24
6.0.23
6.0.22
6.0.21
.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/x64/dotnet
Runtime Versions:
3.1.32
3.1.31
3.1.29
Xamarin.Profiler
Version: 1.8.0.49
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
Updater
Version: 11
Xamarin.Android
Version: 13.2.2.0 (Visual Studio Community)
Commit: xamarin-android/d17-5/45b0e14
Android SDK: /Users/zwells/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
6.0 (API level 23)
12.0 (API level 31)
11.0 (API level 30)
10.0 (API level 29)
7.1 (API level 25)
9.0 (API level 28)
13.0 (API level 33)
7.0 (API level 24)
SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 34.0.3
SDK Build Tools Version: 33.0.0
Build Information:
Mono: d9a6e87
Java.Interop: xamarin/java.interop/d17-5@149d70fe
SQLite: xamarin/sqlite/3.40.1@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d
Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.16.1
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Android SDK Manager
Version: 17.6.0.50
Hash: a715dca
Branch: HEAD
Build date: 2023-11-10 12:19:52 UTC
Android Device Manager
Version: 0.0.0.1309
Hash: 06e3e77
Branch: HEAD
Build date: 2023-11-10 12:19:52 UTC
Xamarin Designer
Version: 17.6.3.9
Hash: 2648399ae8
Branch: remotes/origin/d17-6
Build date: 2023-11-10 12:19:46 UTC
Apple Developer Tools
Xcode: 15.1 22502
Build: 15C5059c
Xamarin.Mac
Not Installed
Xamarin.iOS
Version: 16.4.0.23 Visual Studio Community
Hash: 9defd91b3
Branch: xcode14.3
Build date: 2023-10-23 16:15:00-0400
Build Information
Release ID: 1706070417
Git revision: 179aa48a5702754e41a8218d0403ddc3be46706f
Build date: 2023-11-10 12:18:09+00
Build branch: release-17.6
Build lane: release-17.6
Operating System
Mac OS X 14.1.1
Darwin 23.1.0 Darwin Kernel Version 23.1.0
Mon Oct 9 21:28:31 PDT 2023
root:xnu-10002.41.9~6/RELEASE_ARM64_T8112 arm64
Enabled user installed extensions
NuGet Package Explorer 0.12
NuGet Package Management Extensions 0.34
Build Logs
SAV.iOS_Release_iPhone_Build_2023-12-05T16_34_30.5478590Z.msbuild.log.zip