Bug 8325 - AdoptsAttribute protocol handles not matching up with handles to ConformsToProtocol
Summary: AdoptsAttribute protocol handles not matching up with handles to ConformsToPr...
Alias: None
Product: MonoMac
Classification: Desktop
Component: Bindings ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-11-10 02:18 UTC by Justin Aquadro
Modified: 2015-02-17 14:42 UTC (History)
2 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 Justin Aquadro 2012-11-10 02:18:51 UTC
This appears to the be the root bug of objects implementing the NSPasteboardReading / NSPasteboardWriting protocols being rejected by the pasteboard functions with "does not implement protocol X" errors, even though all required protocol methods are implemented and [Adopts("NSPasteboardWriting")] and [Adopts("NSPasteboardReading")] attributes are present on the class.

Given the following alternate code:

public class MyClipboardData : NSPasteboardReading {

static AdoptsAttribute _writingProtocol = new AdoptsAttribute ("NSPasteboardWriting");
static AdoptsAttribute _readingProtocol = new AdoptsAttribute ("NSPasteboardReading");

public override bool ConformsToProtocol (IntPtr protocol)
	if (protocol == _readingProtocol.ProtocolHandle)
		return true;
	if (protocol == _writingProtocol.ProtocolHandle)
		return true;
	return base.ConformsToProtocol (protocol);

MyClipboardData dataItem = new MyClipboardData(data);
NSPasteboard pasteboard = NSPasteboard.GeneralPasteboard;
pasteboard.WriteObjects(new NSPasteboardReading[] { dataItem });

The program will step into the ConformsToProtocol override upon the call to pasteboard.WriteObjects, but it will not match the NSPasteboardWriting protocol handle, or anything in the base call.  Simply returning true in ConformsToProtocol will allow the WriteObjects call to succeed.  I was hoping to use the objc protocol_getName routine to get a better idea of what's happening, but importing it crashes the runtime.

Version Information:

Installation UUID: 323563aa-b34c-4916-90fd-c6dc6d763b58
	Mono 2.10.9 (tarball)
	GTK 2.24.10
	GTK# (
	Package version: 210090011
Apple Developer Tools:
	 Xcode 4.5.2 (1847)
	 Build 4G2008a
Mono for Android: Not Installed

Build information:
	Release ID: 30004007
	Git revision: ea0108260c6a376ecaeffcdb7d03387bd51edda3
	Build date: 2012-09-17 14:09:17+0000
	Xamarin addins: ec43fd5cb223ead4234a9858d1b56eef03dad53a-dirty
Operating System:
	Mac OS X 10.8.2
	Darwin Justins-Mac-mini.local 12.2.1 Darwin Kernel Version 12.2.1
	    Thu Oct 18 12:13:47 PDT 2012
	    root:xnu-2050.20.9~1/RELEASE_X86_64 x86_64
Comment 1 Chris Hamons 2015-02-17 14:42:12 UTC
Hey Justin,

Apologies in the long delay in responding to this bug. It was misfiled and overlooked.

I believe we've fixed this in Xamarin.Mac 1.10. In 1.12 (Alpha/Beta right now), we have improved protocol support that makes this even easier to work with.

Feel free to try out those version and open a new bug if there is still issues.

Sorry again for the delay,

-- Chris H