Bug 37310 - Incorrect Binding for HealthKit HKStatisticsCollectionQuery.StatisticsUpdateHandler
Summary: Incorrect Binding for HealthKit HKStatisticsCollectionQuery.StatisticsUpdateH...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.4 (iOS 9.2)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2015-12-29 01:47 UTC by Brian
Modified: 2016-01-04 21:50 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Brian 2015-12-29 01:47:23 UTC
The type for the StatisticsUpdateHandler property on HealthKit.HKStatisticsCollectionQuery seems incorrect. It is currently the delegate:

HKStatisticsCollectionQueryInitialResultsHandler(HKStatisticsCollectionQuery query, HKStatisticsCollection result, NSError error)

But it should be:

HKStatisticsCollectionQueryStatisticsUpdateHandler(HKStatisticsCollectionQuery query, HKStatistics statistics, HKStatisticsCollection collection, NSError error)

Note: HKStatisticsCollectionQueryStatisticsUpdateHandler does not exist at all, I just named it to match the pattern of the first handler.

Apple Docs: https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HKStatisticsCollectionQuery_Class/index.html#//apple_ref/occ/instp/HKStatisticsCollectionQuery/statisticsUpdateHandler

Assigning a delegate with HKStatisticsCollectionQueryInitialResultsHandler signature seems to be causing the app to crash when called with output:

Unhandled Exception:
System.InvalidCastException: Specified cast is not valid.
  at (wrapper castclass) System.Object:__castclass_with_cache (object,intptr,intptr)
  at ObjCRuntime.Runtime.ConstructNSObject[T] (IntPtr ptr, System.Type type, MissingCtorResolution missingCtorResolution) [0x0003e] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/ObjCRuntime/Runtime.cs:790 
  at ObjCRuntime.Runtime.GetNSObject[T] (IntPtr ptr) [0x000e4] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/ObjCRuntime/Runtime.cs:902 
  at ObjCRuntime.Trampolines+SDHKStatisticsCollectionQueryInitialResultsHandler.Invoke (IntPtr block, IntPtr query, IntPtr result, IntPtr error) [0x00019] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/build/ios/native/ObjCRuntime/Trampolines.g.cs:10349 
  at (wrapper native-to-managed) ObjCRuntime.Trampolines+SDHKStatisticsCollectionQueryInitialResultsHandler:Invoke (intptr,intptr,intptr,intptr)
2015-12-28 20:07:04.835 APPNAME[12280:1644688] Unhandled managed exception:
Specified cast is not valid. (System.InvalidCastException)
  at (wrapper castclass) System.Object:__castclass_with_cache (object,intptr,intptr)
  at ObjCRuntime.Runtime.ConstructNSObject[T] (IntPtr ptr, System.Type type, MissingCtorResolution missingCtorResolution) [0x0003e] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/ObjCRuntime/Runtime.cs:790 
  at ObjCRuntime.Runtime.GetNSObject[T] (IntPtr ptr) [0x000e4] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/ObjCRuntime/Runtime.cs:902 
  at ObjCRuntime.Trampolines+SDHKStatisticsCollectionQueryInitialResultsHandler.Invoke (IntPtr block, IntPtr query, IntPtr result, IntPtr error) [0x00019] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/build/ios/native/ObjCRuntime/Trampolines.g.cs:10349 
  at (wrapper native-to-managed) ObjCRuntime.Trampolines+SDHKStatisticsCollectionQueryInitialResultsHandler:Invoke (intptr,intptr,intptr,intptr)
2015-12-28 20:07:04.835 APPNAMEIOS[12280:1644688] critical: Stacktrace:

2015-12-28 20:07:04.836 APPNAMEIOS[12280:1644688] critical: 
Native stacktrace:

2015-12-28 20:07:04.843 APPNAMEIOS[12280:1644688] critical: 	0   libmonosgen-2.0.dylib               0x05b877a7 mono_handle_native_sigsegv + 311
2015-12-28 20:07:04.844 APPNAMEIOS[12280:1644688] critical: 	1   libmonosgen-2.0.dylib               0x05bdd661 sigabrt_signal_handler + 145
2015-12-28 20:07:04.844 APPNAMEIOS[12280:1644688] critical: 	2   libsystem_platform.dylib            0x0706303b _sigtramp + 43
2015-12-28 20:07:04.844 APPNAMEIOS[12280:1644688] critical: 	3   ???                                 0xffffffff 0x0 + 4294967295
2015-12-28 20:07:04.845 APPNAMEIOS[12280:1644688] critical: 	4   libsystem_c.dylib                   0x06df965d abort + 156
2015-12-28 20:07:04.845 APPNAMEIOS[12280:1644688] critical: 	5   APPNAMEIOS             0x00175ed6 xamarin_unhandled_exception_handler + 342
2015-12-28 20:07:04.845 APPNAMEIOS[12280:1644688] critical: 	6   libmonosgen-2.0.dylib               0x05b8802b mono_invoke_unhandled_exception_hook + 91
2015-12-28 20:07:04.845 APPNAMEIOS[12280:1644688] critical: 	7   libmonosgen-2.0.dylib               0x05b86e8d mono_handle_exception_internal + 6061
2015-12-28 20:07:04.845 APPNAMEIOS[12280:1644688] critical: 	8   libmonosgen-2.0.dylib               0x05b856d9 mono_handle_exception + 41
2015-12-28 20:07:04.845 APPNAMEIOS[12280:1644688] critical: 	9   libmonosgen-2.0.dylib               0x05bd7d4e mono_x86_throw_exception + 142
2015-12-28 20:07:04.846 APPNAMEIOS[12280:1644688] critical: 	10  ???                                 0x15b7df57 0x0 + 364371799
2015-12-28 20:07:04.846 APPNAMEIOS[12280:1644688] critical: 	11  ???                                 0x175c7928 0x0 + 391936296
2015-12-28 20:07:04.846 APPNAMEIOS[12280:1644688] critical: 	12  ???                                 0x175d515c 0x0 + 391991644
2015-12-28 20:07:04.846 APPNAMEIOS[12280:1644688] critical: 	13  ???                                 0x189e630c 0x0 + 413033228
2015-12-28 20:07:04.846 APPNAMEIOS[12280:1644688] critical: 	14  ???                                 0x189e5e34 0x0 + 413031988
2015-12-28 20:07:04.847 APPNAMEIOS[12280:1644688] critical: 	15  HealthKit                           0x057f59f6 __77-[HKStatisticsCollectionQuery _queue_deliverResetStatisticsObjects:forQuery:]_block_invoke + 52
2015-12-28 20:07:04.847 APPNAMEIOS[12280:1644688] critical: 	16  libdispatch.dylib                   0x06d0f9f3 _dispatch_call_block_and_release + 15
2015-12-28 20:07:04.847 APPNAMEIOS[12280:1644688] critical: 	17  libdispatch.dylib                   0x06d2d6fd _dispatch_client_callout + 14
2015-12-28 20:07:04.847 APPNAMEIOS[12280:1644688] critical: 	18  libdispatch.dylib                   0x06d1533e _dispatch_queue_drain + 1065
2015-12-28 20:07:04.848 APPNAMEIOS[12280:1644688] critical: 	19  libdispatch.dylib                   0x06d14c89 _dispatch_queue_invoke + 563
2015-12-28 20:07:04.848 APPNAMEIOS[12280:1644688] critical: 	20  libdispatch.dylib                   0x06d16732 _dispatch_root_queue_drain + 442
2015-12-28 20:07:04.848 APPNAMEIOS[12280:1644688] critical: 	21  libdispatch.dylib                   0x06d16571 _dispatch_worker_thread3 + 108
2015-12-28 20:07:04.849 APPNAMEIOS[12280:1644688] critical: 	22  libsystem_pthread.dylib             0x0704f653 _pthread_wqthread + 724
2015-12-28 20:07:04.849 APPNAMEIOS[12280:1644688] critical: 	23  libsystem_pthread.dylib             0x0704ce0e start_wqthread + 30
2015-12-28 20:07:04.849 APPNAMEIOS[12280:1644688] critical: 
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
Comment 1 Sebastien Pouliot 2016-01-04 21:50:25 UTC
This was a binding mistake and will be corrected in our next preview.

Fixed in maccore/master b922beba06f0c8626ec20a32bb081b2a78ede9de