Bug 8712 - Unexpected NULL reference in Bindings project
Summary: Unexpected NULL reference in Bindings project
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.0.x
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: (C10)
Assignee: Alex Soto [MSFT]
Depends on:
Reported: 2012-12-01 16:55 UTC by René Ruppert
Modified: 2016-10-14 14:17 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 René Ruppert 2012-12-01 16:55:22 UTC
Attached find two solutions:
1. A bindings project of PSPDFKit
2. A demo project called PSPDFTest

The background of this issue:
In the ObjC version, PSPDFKit uses a dictionary to allow subclassing. The PSPDFViewController interface has an overrideClassNames property of type NSDictionary.
Into this dictionary, one feeds the type of the default class and the type of the specific class one wants to have created at runtime.
The ObjC version looks like this to override PDPFFileAnnotationProvider with a custom class: 

pdfController.overrideClassNames = @{(id)[PDPFFileAnnotationProvider class] : [CustomFileAnnotationProvider class]};

this translates to MonoTouch:

oClassDic.LowlevelSetObject(new Class(typeof(CustomFileAnnotationProvider)).Handle, new Class(typeof(PSPDFFileAnnotationProvider)).Handle);

If you run the demo project, you'll see the output:

Console.WriteLine("*** CustomFileAnnotationProvider(IntPtr)");

But then the project crashes. This is unexpected because the failing constructor is also binded.


  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_UInt32 (intptr,intptr,uint) <IL 0x00027, 0xffffffff>
  at AlexTouch.PSPDFKit.PSPDFDocument.AnnotationParserForPage (uint) <IL 0x00033, 0x000f7>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_object__this___int (object,intptr,intptr,intptr) <IL 0x00056, 0xffffffff>
  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr) <IL 0x00024, 0xffffffff>
  at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:124
  at PSPDFTest.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication,MonoTouch.Foundation.NSDictionary) [0x00036] in /Users/rene/Documents/Develop/PSPDFKit/PSPDFTest/PSPDFTest/AppDelegate.cs:34
  at (wrapper runtime-invoke) <Module>.runtime_invoke_bool__this___object_object (object,intptr,intptr,intptr) <IL 0x00066, 0xffffffff>
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
  at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at PSPDFTest.Application.Main (string[]) [0x00000] in /Users/rene/Documents/Develop/PSPDFKit/PSPDFTest/PSPDFTest/Main.cs:17
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

	0   PSPDFTest                           0x001bfcdc mono_handle_native_sigsegv + 284
	1   PSPDFTest                           0x00134a68 mono_sigsegv_signal_handler + 248
	2   libsystem_c.dylib                   0x9905386b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   PSPDFTest                           0x00124a59 -[PSPDFFileAnnotationProvider initWithDocumentProvider:] + 361
	5   PSPDFTest                           0x0008dabc -[PSPDFAnnotationParser initWithDocumentProvider:] + 268
	6   PSPDFTest                           0x0005a234 -[PSPDFDocumentProvider annotationParser] + 170
	7   PSPDFTest                           0x00011bb4 -[PSPDFDocument annotationParserForPage:] + 96
Comment 2 Sebastien Pouliot 2016-10-03 21:40:14 UTC
I suspect it dos not happen anymore, but better be sure :)
Comment 3 Alex Soto [MSFT] 2016-10-14 14:17:03 UTC
I just tried this with the latest version of PSPDFKit + X.I and it does not crash anymore.