Bug 2021 - App crashes when using UIReferenceLibraryViewController
Summary: App crashes when using UIReferenceLibraryViewController
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-11-14 05:13 UTC by uru
Modified: 2012-01-16 08:46 UTC (History)
3 users (show)

Tags:
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:
Status:
RESOLVED FIXED

Description uru 2011-11-14 05:13:53 UTC
I made a simple application with UIReferenceLibraryViewController.But application crashes with this code.

MyButton.TouchDown += delegate {
	var vc = new UIReferenceLibraryViewController("hello");
	this.NavigationController.PresentModalViewController(vc,true);
};


Application output is this.

=======================================================
2011-11-14 18:58:17.176 DictTest[1440:1907] -[UIReferenceLibraryViewController initWithTerm]: unrecognized selector sent to instance 0x11eac430

Unhandled Exception: MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UIReferenceLibraryViewController initWithTerm]: unrecognized selector sent to instance 0x11eac430
  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:IntPtr_objc_msgSend_IntPtr (intptr,intptr,intptr)
  at MonoTouch.UIKit.UIReferenceLibraryViewController..ctor (System.String term) [0x0002e] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIReferenceLibraryViewController.g.cs:98 
  at DictTest.FirstViewController.<ViewDidLoad>m__0 (System.Object , System.EventArgs ) [0x00000] in <filename unknown>:0 
  at MonoTouch.UIKit.UIControlEventProxy.Activated () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIControl.cs:30 
  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 DictTest.Application.Main (System.String[] args) [0x00000] in <filename unknown>:0 
=======================================================
Comment 1 Rolf Bjarne Kvinge [MSFT] 2011-11-21 09:07:50 UTC
You need to put the vc variable at class level, otherwise the GC will free it since it doesn't know objective c has a reference to it.

Please reopen if this change doesn't fix it for you.
Comment 2 uru 2011-12-07 09:13:36 UTC
I wrote this code but failed with exception.
=======================================================
using MonoTouch.UIKit;
using System.Drawing;
using System;
using MonoTouch.Foundation;

namespace DictTest
{
	public partial class DictTestViewController : UIViewController
	{
		public DictTestViewController () : base ("DictTestViewController", null)
		{
		}
		
		static UIReferenceLibraryViewController foo;
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			MyButton.TouchDown += delegate {
				foo = new UIReferenceLibraryViewController("Hello");
			};
		}
	}
}
=======================================================
Unhandled Exception: MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UIReferenceLibraryViewController initWithTerm]: unrecognized selector sent to instance 0x99fb880
Comment 3 Rolf Bjarne Kvinge [MSFT] 2011-12-09 09:55:45 UTC
That's a problem with UIReferenceLibraryViewController, and you didn't show the source for that class.
Comment 4 Sebastien Pouliot 2012-01-16 08:46:01 UTC
This was a typo in the selector (missing `:`) that made the constructor fail.
The `dictionaryHasDefinitionForTerm` had the same typo (fixed too).
Fixed for 5.1.3 (beta) and the next stable (5.0.x) release.