Bug 942 - Wrong binding for CGPDFArray.GetDictionary()
Summary: Wrong binding for CGPDFArray.GetDictionary()
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 4.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-09-20 16:51 UTC by René Ruppert
Modified: 2011-09-21 14:51 UTC (History)
3 users (show)

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


Attachments
assembly w/pdf related fixes (2.26 MB, application/octet-stream)
2011-09-21 14:51 UTC, Sebastien Pouliot
Details


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 René Ruppert 2011-09-20 16:51:40 UTC
MT 4.2 beta

CGPDFArray.GetDictionary() returns a CGPDFArray as output instead of a CGPDFDictionary, as it is in ObjC:

CGPDFArrayRef pageAnnotations = NULL;
CGPDFDictionaryRef pageDictionary = CGPDFPageGetDictionary(_PDFPageRef);
CGPDFDictionaryGetArray(pageDictionary, "Annots", &pageAnnotations);
CGPDFDictionaryRef annotationDictionary = NULL;
// Here the output is correct: CGPDFDictionaryRef
CGPDFArrayGetDictionary(pageAnnotations, index, &annotationDictionary);


In Monotouch it is:

CGPDFArray.GetDictionary(int idx, out CGPDFArray result)

should be:

CGPDFArray.GetDictionary(int idx, out CGPDFDictionary result)
Comment 1 Sebastien Pouliot 2011-09-20 17:18:29 UTC
Good catch!

http://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGPDFArray/Reference/reference.html

In the mean time (and as a workaround until a fixed version is released) you can use something like below in your own application by using the CGPDFArray.Handle property for the first parameter.

[DllImport (Constants.CoreGraphicsLibrary)]
extern static bool CGPDFArrayGetDictionary (IntPtr handle, IntPtr idx, out IntPtr result);

public bool GetDictionary (IntPtr handle, int idx, out CGPDFDictionary result)
{
	IntPtr res;
	var r = CGPDFArrayGetDictionary (handle, (IntPtr) idx, out res);
	if (!r){
		result = null;
		return false;
	}
	result = new CGPDFDictionary (res);
	return true;
}
Comment 2 Sebastien Pouliot 2011-09-20 21:29:46 UTC
Fixed in a2b400bc84f9d24bac2ec0829814e504ad1c8178 (master).
Thanks for the report!
Comment 3 René Ruppert 2011-09-21 03:44:48 UTC
Is there a way to get access to a build of this? I don't really care if it is pre-alpha - I just assume you didn't break lots of other things! :-)
Meanwhile I have used a workaround exactly as you proposed and it works just fine.
Comment 4 Sebastien Pouliot 2011-09-21 13:50:06 UTC
I backported this fix to our monotouch-4.2 branch (along with Miguel's CGPDFDictionary.Apply patch) so they'll both be available in future (post 4.2.1) versions. I'll attach a newer monotouch.dll to the this bug report later today so you can use it on top of 4.2.1.
Comment 5 Sebastien Pouliot 2011-09-21 14:51:25 UTC
Created attachment 460 [details]
assembly w/pdf related fixes

First wait until you have monotouch 4.2.1 installed (less likely to break things)
Then backup /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll and /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb
Next copy the attachment over /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll
Delete /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb
Rebuild your code and it should be ok

note #1: once you update MonoTouch to 4.2.2+ it will overwrite this assembly - but since the fixes are both in 'master' and 'monotouch-4.2' branches then it should not affect you.

note #2: if you run into weird errors please re-install the original (backup) assembly (and symbols) before reporting the bug to ensure we'll work on the same code base as you to duplicate any issue :-)