Bug 8144 - Exception when specifying NSLayoutAttribute.NoAttribute in NSLayoutConstraint.Create
Summary: Exception when specifying NSLayoutAttribute.NoAttribute in NSLayoutConstraint...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-11-01 13:13 UTC by Len Charest
Modified: 2012-11-01 13:48 UTC (History)
2 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 Len Charest 2012-11-01 13:13:24 UTC
Using NSLayoutConstraint.Create with NSLayoutAttribute.NoAttribute as the value of attribute2 causes a run-time exception as follows:

"MonoTouch.Foundation.MonoTouchException has been thrown

Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: *** +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: Unknown layout attribute"

NSLayoutAttribute.NoAttribute should map to NSLayoutAttributeNotAnAttribute in Objective-C, which is supposed to be supported by constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant: (the Obj-C method that NSLayoutConstraint.Create maps to).

Additionally, it would be nice if were possible to pass null as the value of view2 in NSLayoutConstraint.Create (the equivalent of passing nil as the value of view2 in constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:).
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-11-01 13:48:44 UTC
Fixed.

You're getting the "Unknown layout attribute" because you're not passing null for the second view - so making it possible to pass null for the second view makes the error go away too.

There is an ugly workaround you can use until this fix is included in a release: pass a disposed NSObject instead of null (the important part is that its Handle must be IntPtr.Zero).

master: 77672425c5126b3fbb2f01d527742514132dbf3f
ios6: 9fdcda09ec0a6605ca563866cd15b81c63db60c8