Bug 37390 - HealthKit HKWorkout.Create incorrectly throws ArgumentNullException
Summary: HealthKit HKWorkout.Create incorrectly throws ArgumentNullException
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.8 (tvOS / C7)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-04 20:27 UTC by Brian
Modified: 2016-01-04 22:14 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 2016-01-04 20:27:07 UTC
Static Create functions on HKWorkout should allow null values for "totalEnergyBurned" and "totalDistance", both of type HKQuantity.

The following overload throws an ArgumentNullException:
public static HKWorkout Create(HKWorkoutActivityType workoutActivityType, NSDate startDate, NSDate endDate, double duration, HKQuantity totalEnergyBurned, HKQuantity totalDistance, NSDictionary metadata);

Xamarin Docs: https://developer.xamarin.com/api/member/HealthKit.HKWorkout.Create/p/HealthKit.HKWorkoutActivityType/Foundation.NSDate/Foundation.NSDate/System.Double/HealthKit.HKQuantity/HealthKit.HKQuantity/Foundation.NSDictionary/

Apple Docs (showing "nil" is allowed):
https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HKWorkout_Class/index.html#//apple_ref/occ/clm/HKWorkout/workoutWithActivityType:startDate:endDate:duration:totalEnergyBurned:totalDistance:metadata:


I tested a different overload, which worked correctly, but is only available as of iOS9:
public static HKWorkout Create(HKWorkoutActivityType workoutActivityType, NSDate startDate, NSDate endDate, double duration, HKQuantity totalEnergyBurned, HKQuantity totalDistance, HKDevice device, NSDictionary metadata);

Xamarin Docs: https://developer.xamarin.com/api/member/HealthKit.HKWorkout.Create/p/HealthKit.HKWorkoutActivityType/Foundation.NSDate/Foundation.NSDate/System.Double/HealthKit.HKQuantity/HealthKit.HKQuantity/HealthKit.HKDevice/Foundation.NSDictionary/

Apple Docs: https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HKWorkout_Class/index.html#//apple_ref/occ/clm/HKWorkout/workoutWithActivityType:startDate:endDate:duration:totalEnergyBurned:totalDistance:device:metadata:
Comment 1 Sebastien Pouliot 2016-01-04 22:14:10 UTC
Other Create overloads signatures were ok but the one you mention was missing [NullAllowed] attributes.

Fixed in maccore/master 75ae4dc7498f703d8c6712611686812a30a912da