This appears to have been confirmed over a year ago, but never followed up on: https://bugzilla.xamarin.com/show_bug.cgi?id=52476.
NSObject using the Xamarin AddObserver overloads that takes a function as an argument.Receive observer notifications normally.
A warning in the logs, followed by a thread crash as soon as the observer executes. Note that in my usage, nothing should be deallocated so I'm not sure why the error message about Dispose shows up (the view is still on screen, and the object being observed is a persistent ivar). The crash occurs even with a completely empty observer method.
I would also add that the way in which the app "crashes" is also completely unexpected. The app freezes, but there is no other indication that something is wrong unless you look at the logs. Not a fan of how the runtime handles this.
=== Visual Studio Community 2017 for Mac ===
Version 7.5.3 (build 7)
Installation UUID: 588f3763-d580-45de-b809-10d8518368e1
Runtime:
Mono 5.10.1.57 (2017-12/ea8a24b1bbf) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)
Package version: 510010057
=== NuGet ===
Version: 4.3.1.4445
=== .NET Core ===
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.1.1
2.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.301/Sdks
SDK Versions:
2.1.301
2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/msbuild/15.0/bin/Sdks
=== Xamarin.Profiler ===
Version: 1.6.2
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
=== Xamarin.Android ===
Version: 8.3.3.2 (Visual Studio Community)
Android SDK: /Users/ianthetechie/Library/Android/sdk
Supported Android versions:
6.0 (API level 23)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 27.0.3
Java SDK: /usr
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
=== Xamarin Inspector ===
Version: 1.4.0
Hash: b3f92f9
Branch: master
Build date: Fri, 19 Jan 2018 22:00:34 GMT
Client compatibility: 1
=== Apple Developer Tools ===
Xcode 9.4.1 (14161)
Build 9F2000
=== Xamarin.Mac ===
Version: 4.4.1.193 (Visual Studio Community)
=== Xamarin.iOS ===
Version: 11.12.0.4 (Visual Studio Community)
Hash: 64fece5f
Branch: d15-7
Build date: 2018-05-29 20:00:44-0400
=== Build Information ===
Release ID: 705030007
Git revision: 13cecd02aceddf29a1ed57b86f81c02994df1483
Build date: 2018-06-14 15:48:08-04
Xamarin addins: 7065de97cf22c9038fdc39dd627f2c30790fd8af
Build lane: monodevelop-lion-d15-7
=== Operating System ===
Mac OS X 10.13.5
Darwin 17.6.0 Darwin Kernel Version 17.6.0
Tue May 8 15:22:16 PDT 2018
root:xnu-4570.61.1~1/RELEASE_X86_64 x86_64
=== Enabled user installed addins ===
NuGet Package Management Extensions 0.13
Internet of Things (IoT) development (Preview) 7.5
2018-07-06 19:51:00.975 MyChurch.iOS[54474:1313072] Warning: observer object was not disposed manually with Dispose()
Thread finished: <Thread Pool> #8
2018-07-06 19:51:08.829 MyChurch.iOS[54474:1313010] critical: Stacktrace:
2018-07-06 19:51:08.830 MyChurch.iOS[54474:1313010] critical: at <unknown> <0xffffffff>
2018-07-06 19:51:08.830 MyChurch.iOS[54474:1313010] critical: at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) [0x0005c] in <0b60c1467e7449608ac42f9c7bbfdd05>:0
2018-07-06 19:51:08.830 MyChurch.iOS[54474:1313010] critical: at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIApplication.cs:79
2018-07-06 19:51:08.831 MyChurch.iOS[54474:1313010] critical: at UIKit.UIApplication.Main (string[],string,string) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIApplication.cs:63
2018-07-06 19:51:08.831 MyChurch.iOS[54474:1313010] critical: at MyChurch.iOS.Application.Main (string[]) [0x00001] in /Users/ianthetechie/Projects/MyChurch/iOS/Main.cs:11
2018-07-06 19:51:08.831 MyChurch.iOS[54474:1313010] critical: at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x00051] in <7a75af06829442cf9a5b3c74e02ebd1f>:0
2018-07-06 19:51:08.831 MyChurch.iOS[54474:1313010] critical:
Native stacktrace:
2018-07-06 19:51:08.876 MyChurch.iOS[54474:1313010] critical: 0 MyChurch.iOS 0x0000000108e671b4 mono_handle_native_crash + 244
2018-07-06 19:51:08.876 MyChurch.iOS[54474:1313010] critical: 1 MyChurch.iOS 0x0000000108e765e0 mono_sigsegv_signal_handler + 288
2018-07-06 19:51:08.877 MyChurch.iOS[54474:1313010] critical: 2 libsystem_platform.dylib 0x000000011857cf5a _sigtramp + 26
2018-07-06 19:51:08.877 MyChurch.iOS[54474:1313010] critical: 3 MyChurch.iOS 0x0000000108fe5f84 sgen_gchandle_get_target + 180
2018-07-06 19:51:08.877 MyChurch.iOS[54474:1313010] critical: 4 Foundation 0x000000010a40b259 NSKeyValueWillChangeWithPerThreadPendingNotifications + 294
2018-07-06 19:51:08.878 MyChurch.iOS[54474:1313010] critical: 5 AVFoundation 0x000000010a992493 -[AVPlayer willChangeValueForKey:] + 85
2018-07-06 19:51:08.878 MyChurch.iOS[54474:1313010] critical: 6 AVFoundation 0x000000010a995f19 __67-[AVPlayer _createAndConfigureFigPlayerWithType:completionHandler:]_block_invoke_2 + 162
2018-07-06 19:51:08.878 MyChurch.iOS[54474:1313010] critical: 7 libdispatch.dylib 0x0000000117f9d6cb _dispatch_call_block_and_release + 12
2018-07-06 19:51:08.878 MyChurch.iOS[54474:1313010] critical: 8 libdispatch.dylib 0x0000000117f9e709 _dispatch_client_callout + 8
2018-07-06 19:51:08.879 MyChurch.iOS[54474:1313010] critical: 9 libdispatch.dylib 0x0000000117fa8708 _dispatch_main_queue_callback_4CF + 1279
2018-07-06 19:51:08.879 MyChurch.iOS[54474:1313010] critical: 10 CoreFoundation 0x000000010974bc99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
2018-07-06 19:51:08.879 MyChurch.iOS[54474:1313010] critical: 11 CoreFoundation 0x000000010970fea6 __CFRunLoopRun + 2342
2018-07-06 19:51:08.879 MyChurch.iOS[54474:1313010] critical: 12 CoreFoundation 0x000000010970f30b CFRunLoopRunSpecific + 635
2018-07-06 19:51:08.880 MyChurch.iOS[54474:1313010] critical: 13 GraphicsServices 0x000000011b02ca73 GSEventRunModal + 62
2018-07-06 19:51:08.880 MyChurch.iOS[54474:1313010] critical: 14 UIKit 0x000000010e210057 UIApplicationMain + 159
2018-07-06 19:51:08.880 MyChurch.iOS[54474:1313010] critical: 15 ??? 0x0000000137f05607 0x0 + 5233464839
2018-07-06 19:51:08.880 MyChurch.iOS[54474:1313010] critical: 16 ??? 0x0000000137f05373 0x0 + 5233464179
2018-07-06 19:51:08.881 MyChurch.iOS[54474:1313010] critical:
=================================================================
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.
=================================================================
I can provide one on request, but it seems one was already provided in the past.
Ok, I feel like a doofus...
C# memory management is different from typical iOS memory management, and the behavior is particularly unexpected when it comes to things like observers. What was happening was that the returned value is an IDisposable and you need to retain a reference to it or it will immediately go out of scope.
As a native iOS developer, I find this behavior surprising, but I understand this is fairly logical from the C# perspective (despite resulting in a pattern of essentially useless ivars I find rather annoying). Sorry for the bad report.
Most helpful comment
Ok, I feel like a doofus...
C# memory management is different from typical iOS memory management, and the behavior is particularly unexpected when it comes to things like observers. What was happening was that the returned value is an
IDisposableand you need to retain a reference to it or it will immediately go out of scope.As a native iOS developer, I find this behavior surprising, but I understand this is fairly logical from the C# perspective (despite resulting in a pattern of essentially useless ivars I find rather annoying). Sorry for the bad report.