Bug 59049 - IUIDropSession LoadObjects API difficulities
Summary: IUIDropSession LoadObjects API difficulities
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 10.99 (xcode9)
Hardware: PC Mac OS
: High normal
Target Milestone: Xcode9
Assignee: Vincent Dondain [MSFT]
Depends on:
Reported: 2017-08-25 17:27 UTC by Chris Hamons
Modified: 2017-09-12 02:38 UTC (History)
4 users (show)

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:

Description Chris Hamons 2017-08-25 17:27:47 UTC
I've created a simple drag and drop sample here:


with a custom view that you can drag into the table. However, inside PerformDrop:

			// BUG
			Console.WriteLine ("PerformDrop");
			var destPath = coordinator.DestinationIndexPath;

			if (coordinator.Session.CanLoadObjects (typeof (NSString))) {
				coordinator.Session.LoadObjects (typeof (NSString), (items => {
					Console.WriteLine ("LoadObjects");

					// I would expect this to work
					var strings = items as NSString[];
					Console.WriteLine (strings == null);

					// But the underlying item is a string
					var v = ObjCRuntime.Runtime.GetNSObject<NSString> (items[0].Handle);
					Console.WriteLine (v);

The array passed in does _not_ cast to NSString, even after I fix https://bugzilla.xamarin.com/show_bug.cgi?id=59044 locally.

This seems less than ideal, and if I'm not making a mistake the API rather difficult to use.
Comment 1 Vincent Dondain [MSFT] 2017-09-08 21:47:07 UTC
This also happens with `NSItemProvider.LoadObject`:

var progress = itemProvider.LoadObject (typeof (UIImage), (droppedImage, _) => {
		//var image = ObjCRuntime.Runtime.GetNSObject<UIImage> (droppedImage.Handle);
		//Console.WriteLine (image);
		var image = droppedImage as UIImage;

		DispatchQueue.MainQueue.DispatchAsync (() => {
			if (image != null) {
				var imageView = NewImageView (image);
				imageView.Center = center;
				Images.Add (image);
			} else {
				Console.WriteLine ("Why is the image null??????");
Comment 2 Vincent Dondain [MSFT] 2017-09-08 22:23:02 UTC
You can reproduce this with https://trello.com/c/qgggzWjx/637-dragdrop-dragboard

- Deploy that on device (easier to test on an iPad).
- Open the photo app alongside the DragBoard app.
- Drag and drop a picture on the board.
- `public void LoadImage (NSItemProvider itemProvider, CGPoint center)` should be triggered.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2017-09-08 23:05:10 UTC
What's the actual type of the objects?
Comment 4 Sebastien Pouliot 2017-09-10 16:55:18 UTC
With the sample (trello) I get a null `droppedImage`, which seems to be different from what Chris describe
Comment 5 Vincent Dondain [MSFT] 2017-09-10 21:35:13 UTC
With the sample (trello) and following my repro steps I get a `Foundation.NSItemProviderReadingWrapper` droppedImage.


`var image = droppedImage as UIImage;`

Gives me a null image.
Comment 6 Vincent Dondain [MSFT] 2017-09-10 21:48:46 UTC
I'm puzzled because the generated code shows:

`class NSItemProviderReadingWrapper : BaseWrapper, INSItemProviderReading`


`class UIImage : NSObject, INSCoding, INSItemProviderReading`
Comment 7 Vincent Dondain [MSFT] 2017-09-10 21:52:11 UTC
Here's the stack trace if I do an explicit cast: https://gist.github.com/VincentDondain/670d1454645ef4339c6dbd313af4fb63
Comment 8 Sebastien Pouliot 2017-09-11 00:50:23 UTC
So you're `droppedImage` is non null ? because mine was (and explains the rest)
Comment 9 Rolf Bjarne Kvinge [MSFT] 2017-09-11 10:35:01 UTC
So this happens because the callback signature promises an instance of a class that implements INSItemProviderReading, and that's exactly what we're providing.

I think I have an idea how I can fix this using a code-behind version.
Comment 10 Rolf Bjarne Kvinge [MSFT] 2017-09-11 11:05:20 UTC