Bug 980 - Cannot use ABPeoplePickerNavigationController after update to 4.2
Summary: Cannot use ABPeoplePickerNavigationController after update to 4.2
Status: CLOSED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 4.x
Hardware: Macintosh Mac OS
: High blocker
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
: 359 ()
Depends on:
Blocks:
 
Reported: 2011-09-22 03:00 UTC by Anders Svedlund
Modified: 2012-01-04 15:39 UTC (History)
4 users (show)

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


Attachments
updated assembly with candidate fix (2.26 MB, application/octet-stream)
2011-09-22 13:17 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:
CLOSED FIXED

Description Anders Svedlund 2011-09-22 03:00:45 UTC
Hello,

After update Monotouch today my app crash when using the ABPeoplePickerNavigationController object....

Here is my code..


ABPeoplePickerNavigationController picker = new ABPeoplePickerNavigationController ();

picker.SelectPerson += delegate(object sender, ABPeoplePickerSelectPersonEventArgs e) {
Console.WriteLine("Test");
};


Error:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at MonoTouch.Utils.BackingField.Get[ABAddressBook] (MonoTouch.AddressBook.ABAddressBook& value, IntPtr handle, System.Converter`2 c) [0x0003c] in /Developer/MonoTouch/Source/monotouch/src/Utils/BackingField.cs:47 
  at MonoTouch.AddressBookUI.ABPeoplePickerNavigationController.get_AddressBook () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/AddressBookUI/ABPeoplePickerNavigationController.cs:89 
  at MonoTouch.AddressBookUI.InternalABPeoplePickerNavigationControllerDelegate.ShouldContinue (MonoTouch.AddressBookUI.ABPeoplePickerNavigationController peoplePicker, IntPtr selectedPerson) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/AddressBookUI/ABPeoplePickerNavigationController.cs:50 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:34 
  at Switchboard.Application.Main (System.String[] args) [0x00000] in /Users/anders/Desktop/Projects/Avancit_Switchboard/Avancit_Switchboard/Main.cs:21
Comment 1 Anders Svedlund 2011-09-22 09:02:40 UTC
forgot this part of the code, but shouldn't matter.

importButton.TouchDown += delegate(object sender, EventArgs e) {
    tabBar.PresentModalViewController (picker, true);
};	

picker.Cancelled += delegate {
        picker.DismissModalViewControllerAnimated (true); 
};

Both theese functions work ok, it only crash when i select a contact. This worked in previous versions.
Comment 2 Sebastien Pouliot 2011-09-22 10:09:13 UTC
I can duplicate the issue.

For reference could you tell us which version of MonoTouch you were previously using ? thanks!
Comment 3 Anders Svedlund 2011-09-22 10:11:57 UTC
4.0.7 i think, i upgraded to 4.2 when it was in beta and noticed this bug, so went back to 4.0.7 in hope it would be resolved until release. But no luck :(
Comment 4 Sebastien Pouliot 2011-09-22 10:18:10 UTC
hmm... we do betas to get feedback and bugs/regressions reports ;-)

Smaller test case:

ABPeoplePickerNavigationController picker = new ABPeoplePickerNavigationController ();
Console.WriteLine (picker.AddressBook);
Comment 5 Anders Svedlund 2011-09-22 10:22:08 UTC
I did google the error and found a mailing list on it.

http://comments.gmane.org/gmane.comp.gnome.mono.monotouch/1316

SO thought it was already reported :) 

With ur test my app instantly crashes with the same error as earlier.
Comment 6 Sebastien Pouliot 2011-09-22 11:55:34 UTC
Ok, so you originally went back to 4.0.7 and it worked, right ? (to limit the
regression search)

I have a patch to fix this but it's not something that has changed since 4.0.7
so I need to dig deeper to find what else could have caused this regression. 

Are you still on 4.2.1 ? If so I can attach the updated assembly to unblock you
(and allow you to tell me if it works as expected for you).
Comment 7 Sebastien Pouliot 2011-09-22 13:17:55 UTC
Created attachment 475 [details]
updated assembly with candidate fix

To use the attached assembly (on top of MonoTouch 4.2.1) do:
1) backup your /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll and /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb files
2) copy the attached file to /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll
3) remove the /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb symbols (they won't match anymore)
4) clean, rebuild and test your application
Comment 8 Anders Svedlund 2011-09-23 02:48:51 UTC
This fix worked, i can now use the ABPeoplePickerNavigationController. 

Should I continue to use this dll until there is an update?
Comment 9 Sebastien Pouliot 2011-09-23 08:05:12 UTC
> This fix worked, i can now use the ABPeoplePickerNavigationController.

I'm glad it works. However this fix (a bad null check) is not related to a recent code change that would make this code regress from 4.0.7. I'll be installing 4.0.3 (last Novell version) this morning to see if I can duplicate the issue (or why I can't).

> Should I continue to use this dll until there is an update?

You can, it's based on the monotouch-4.2 branch so the only differences are a few other fixes (mostly CGPDF-related) that were made on this branch. However if you find other issues please replace the original file (and symbols) before reporting them. Otherwise we might not be able to reproduce them. Of course if it only fails with the new assembly please tell us about that fact too :-)
Comment 10 Sebastien Pouliot 2011-09-23 09:28:49 UTC
Your test case works in both 4.0.3 and 4.0.7 but

   Console.WriteLine (picker.AddressBook);

fails with a NRE (in both previous versions). 

I'm pretty sure that the recent AddressBook changes Jeff made recently are triggering a call to the AddressBook property - which is not always initialized and that will throw the NRE (which is a very old bug). One last check and I'll commit my fix :-)
Comment 11 Sebastien Pouliot 2011-09-23 09:46:58 UTC
fixed - keep the attached assembly until 4.2.2 (or anything more recent is available).
Thanks for the test case!
Comment 12 Sebastien Pouliot 2011-09-29 19:12:35 UTC
*** Bug 359 has been marked as a duplicate of this bug. ***
Comment 13 PJ 2012-01-04 15:39:18 UTC
verified fixed on:
MAC 10.7.2
MonoDevelop 2.8.5
Mono 2.10.8
Monotouch 5.0.4