Bug 14955 - boundingRectWithSize, ios 6.1 - unrecognized selector sent to instance
Summary: boundingRectWithSize, ios 6.1 - unrecognized selector sent to instance
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 7.0.0.x
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-09-24 11:05 UTC by Andrew
Modified: 2013-09-24 13:56 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 Andrew 2013-09-24 11:05:44 UTC
According to Apple's documentation, iOS 6 does support boundingRectWithSize method:


However, an app compiled with Xamarin.iOS 7.0 and runs without a problem on iOs 7, crashes on iOS 6.1 with the following exception:

MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[__NSCFString boundingRectWithSize:options:attributes:context:]: unrecognized selector sent to instance 0xc5a48b0
  at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:RectangleF_objc_msgSend_stret_SizeF_UInt32_IntPtr_IntPtr (System.Drawing.RectangleF&,intptr,intptr,System.Drawing.SizeF,uint,intptr,intptr)
  at MonoTouch.UIKit.NSExtendedStringDrawing.WeakGetBoundingRect (MonoTouch.Foundation.NSString This, SizeF size, NSStringDrawingOptions options, MonoTouch.Foundation.NSDictionary attributes, MonoTouch.Foundation.NSStringDrawingContext context) [0x00028] in /Developer/MonoTouch/Source/monotouch/src/UIKit/NSExtendedStringDrawing.g.cs:72
  at MonoTouch.UIKit.NSExtendedStringDrawing.GetBoundingRect (MonoTouch.Foundation.NSString This, SizeF size, NSStringDrawingOptions options, MonoTouch.UIKit.UIStringAttributes attributes, MonoTouch.Foundation.NSStringDrawingContext context) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/NSExtendedStringDrawing.g.cs:80
  at XamarinIOsTest.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0005b] in /Users/Andrew/Projects/XamarinIOsTest/XamarinIOsTest/AppDelegate.cs:35
  at 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) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at XamarinIOsTest.Application.Main (System.String[] args) [0x00008] in /Users/Andrew/Projects/XamarinIOsTest/XamarinIOsTest/Main.cs:16

Code to reproduce:

var n = new NSString("TEST");
var uiStringAttributes = new UIStringAttributes {
    Font = UIFont.SystemFontOfSize(15),
var res = n.GetBoundingRect(new SizeF(100, 100), NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, uiStringAttributes, new NSStringDrawingContext());

Apple Developer Tools
Xcode 5.0 (3332.22)
Build 5A1412

Version: (Business Edition)
Hash: aa35ba3
Build date: 2013-18-09 16:42:48-0400
Comment 1 Sebastien Pouliot 2013-09-24 13:56:18 UTC
You're right that it existed in iOS6 - but was defined differently back then.

iOS7 NSStringDrawing.h header file

@interface NSString (NSExtendedStringDrawing)

iOS6.1 NSStringDrawing.h header file

@interface NSAttributedString (NSExtendedStringDrawing)

IOW it's more generally available in iOS7 than it was on iOS6.

The managed API has a [Since(7,0)] attribute because it follows the iOS7 pattern. 

If you want to use this feature on iOS6 and avoid this exception (that comes from ObjC) you'll need to use an `NSAttributedString` (not an `NSString`).