Bug 34438 - UIFont.SystemFontOfSize and UIFontWeight.Bold crash
Summary: UIFont.SystemFontOfSize and UIFontWeight.Bold crash
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: iOS ()
Version: 3.11 (C5)
Hardware: PC Windows
: Low normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-09-30 10:15 UTC by Eric
Modified: 2016-12-22 19:46 UTC (History)
6 users (show)

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


Attachments
Simple Classic API app reproducing the exception (27.18 KB, application/x-zip-compressed)
2015-09-30 10:15 UTC, Eric
Details
screenshot (72.03 KB, image/png)
2015-09-30 13:34 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 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 NOT_REPRODUCIBLE

Description Eric 2015-09-30 10:15:17 UTC
Created attachment 13143 [details]
Simple Classic API app reproducing the exception

Running the following code on iOS 7.1 crashes with the parameter "UIFontWeight.Bold". See the attached solution.

UILabel lbl = new UILabel(View.Bounds);
lbl.Text = "Hello world";
lbl.Font = UIFont.SystemFontOfSize(16, UIFontWeight.Bold);
Add(lbl);

Exception text:
"MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: +[UIFont systemFontOfSize:weight:]: unrecognized selector sent to class 0x8a5d5f4"

Leaving "UIFontWeight.Bold" out and just setting the font-size to 16 works fine.
Comment 1 Eric 2015-09-30 10:16:17 UTC
Using the following version info:


Xamarin 3.11.837.0 (f10676f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android 5.1.5.3 (f98871a95a479f6d71b3067b7e5834d41fcb2118)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS 8.10.4.0 (6db87c53c073f4af2f5247fb738a27ea08c094fd)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration 1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 2 Sebastien Pouliot 2015-09-30 11:25:58 UTC
That's because you're running this on an old version of iOS and this specific API was added in iOS 8.2 and is decorated with `[iOS (8,2)]`.

The IDE (at least XS* does) should show a hint that the API requires iOS 8.2. It's then up to you to decide if you want to do a version check (before using the API) or use an older API (available in all versions of iOS you wish to support).

* moving to VS for verification
Comment 3 Eric 2015-09-30 13:25:19 UTC
Thanks for your quick reply. I'm not sure what you mean with 'HINT', but VS2013 doesn't show any hint or warning.

However, I pressed F12 (Go to definition) and in the metadata source file I found the attribute:

[iOS(8, 2)]
public static UIFont SystemFontOfSize(nfloat size, UIFontWeight weight);

I didn't know this existed, but I do now.

I created a quick work-around for now.

Again, thanks for the advice.
Comment 4 Sebastien Pouliot 2015-09-30 13:34:11 UTC
Created attachment 13148 [details]
screenshot

@Eric, I rarely use Windows (even less VS) but I assume XVS does something similar to XS to give "hints" about API availability (see screenshot).

The XVS team will be able to tell you if/how it's done.
Comment 5 Adrian Alonso 2016-05-11 18:44:39 UTC
@eric: please let me know if you still need help with this. Otherwise I will mark it as resolved. Thanks, Adrian
Comment 7 Adrian Alonso 2016-12-22 19:46:49 UTC
Marking as resolved. Please let us know if you still need help with this issue. Thanks, Adrian