Bug 29020 - XiOS crashes with "NSGenericException" when we add a TextField to UIAlertController
Summary: XiOS crashes with "NSGenericException" when we add a TextField to UIAlertCont...
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.8.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-04-13 05:50 UTC by Prashant Cholachagudda
Modified: 2015-04-13 06:38 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 INVALID

Description Prashant Cholachagudda 2015-04-13 05:50:33 UTC
When we add a TextField to the UIAlertController the app crashes on iOS 8.3 with following exception:

Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSGenericException Reason: Unable to install constraint on view.  Does the constraint reference something from outside the subtree of the view?  That's illegal. constraint:<NSLayoutConstraint:0x7c884a80 UITableView:0x7acd5200.left == UIView:0x7c846840.left> view:<UIView: 0x7c8608e0; frame = (0 0; 0 0); layer = <CALayer: 0x7c879c30>>
  at ObjCRuntime.Runtime.ThrowNSException (IntPtr ns_exception) [0x00000] in /Developer/MonoTouch/Source/maccore/src/ObjCRuntime/Runtime.cs:156
  at ObjCRuntime.Runtime.throw_ns_exception (IntPtr exc) [0x00000] in /Developer/MonoTouch/Source/maccore/runtime/Delegates.generated.cs:100
  at at (wrapper native-to-managed) ObjCRuntime.Runtime:throw_ns_exception (intptr)
  at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
  at LocationTest.Application.Main (System.String[] args) [0x00008] in /Users/prashantvc/Projects/LocationTest/LocationTest/Main.cs:42


## Code snippet:

	var alertController = UIAlertController.Create ("Add Account", null, UIAlertControllerStyle.Alert);
	alertController.View.TintColor = UIColor.DarkGray;
	
	//Crashes here
	alertController.AddTextField ((field) => {
		field.Placeholder = "email address";
	});

	alertController.AddAction (UIAlertAction.Create ("Cancel", UIAlertActionStyle.Default, (act) => {})); 
	alertController.AddAction (UIAlertAction.Create ("Add", UIAlertActionStyle.Default, (act) => { })); 
	PresentViewController (alertController, true, null);
Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-04-13 06:38:49 UTC
The same happens with Objective-C, so this is not a bug in Xamarin.iOS:

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Add account" message:nil preferredStyle:UIAlertControllerStyleAlert];
    alertController.view.tintColor = [UIColor darkGrayColor];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"email address";
    }];
    [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSLog (@"cancel");
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"Add" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSLog (@"add");
    }]];
    [self presentViewController:alertController animated:YES completion:nil];

> 2015-04-13 12:12:16.762 simpletestapp[63573:6184660] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7ff953e385d0 UITableView:0x7ff955026c00.left == UIView:0x7ff953e16620.left>
> 	When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
> 2015-04-13 12:12:16.763 simpletestapp[63573:6184660] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7ff953e38620 UITableView:0x7ff955026c00.right == UIView:0x7ff953e16620.right>
> 	When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
> 2015-04-13 12:12:16.763 simpletestapp[63573:6184660] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7ff953e38970 UITableView:0x7ff955026c00.top == UIView:0x7ff953e16620.top>
> 	When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
> 2015-04-13 12:12:16.763 simpletestapp[63573:6184660] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7ff953e39090 UITableView:0x7ff955026c00.bottom == UIView:0x7ff953e16620.bottom>
> 	When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
> 2015-04-13 12:12:16.851 simpletestapp[63573:6184660] View hierarchy unprepared for constraint.
> 	Constraint: <NSLayoutConstraint:0x7ff953e385d0 UITableView:0x7ff955026c00.left == UIView:0x7ff953e16620.left>
> 	Container hierarchy: 
> <UIView: 0x7ff953e10640; frame = (0 0; 0 0); layer = <CALayer: 0x7ff953e0f810>>
>    | <UIView: 0x7ff953e10750; frame = (0 0; 0 0); clipsToBounds = YES; layer = <CALayer: 0x7ff953e0e470>>
>    |    | <_UIAlertControllerShadowedScrollView: 0x7ff953e108b0; frame = (0 0; 0 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7ff953e11420>; layer = <CALayer: 0x7ff953e077b0>; contentOffset: {0, 0}; contentSize: {0, 0}>
>    |    |    | <UIView: 0x7ff953e12110; frame = (0 0; 0 0); layer = <CALayer: 0x7ff953e12220>>
>    |    |    |    | <UILabel: 0x7ff953e13df0; frame = (0 0; 0 0); text = 'Add account'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7ff953e143a0>>
>    |    |    |    | <UILabel: 0x7ff953e15dc0; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7ff953e15f70>>
>    |    |    |    | <UIView: 0x7ff953e16620; frame = (0 0; 0 0); clipsToBounds = YES; layer = <CALayer: 0x7ff953e16730>>
>    |    | <UILabel: 0x7ff953e161f0; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7ff953e163a0>>
>    |    | <UICollectionView: 0x7ff955016400; frame = (0 0; 0 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7ff953e18670>; layer = <CALayer: 0x7ff953e18060>; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: > <_UIAlertControllerCollectionViewFlowLayout: 0x7ff953e16e80>
> 	View not found in container hierarchy: <UITableView: 0x7ff955026c00; frame = (0 20; 375 647); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x7ff953e21f60>; layer = <CALayer: 0x7ff953e21560>; contentOffset: {0, 0}; contentSize: > {375, 25}>
> 	That view's superview: NO SUPERVIEW
> 2015-04-13 12:12:16.856 simpletestapp[63573:6184660] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view.  Does the constraint reference something from outside the subtree of the view?  That's illegal. constraint:<NSLayoutConstraint:0x7ff953e385d0 UITableView:0x7ff955026c00.left == UIView:0x7ff953e16620.left> view:<UIView: 0x7ff953e10640; frame = (0 0; 0 0); layer = <CALayer: 0x7ff953e0f810>>'
> *** First throw call stack:
> (
> 	0   CoreFoundation                      0x00000001049b4c65 __exceptionPreprocess + 165
> 	1   libobjc.A.dylib                     0x000000010464bbb7 objc_exception_throw + 45
> 	2   CoreFoundation                      0x00000001049b4b9d +[NSException raise:format:] + 205
> 	3   Foundation                          0x00000001041dc479 -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 187
> 	4   UIKit                               0x0000000105429a34 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 474
> 	5   Foundation                          0x00000001041ea1be -[NSISEngine withBehaviors:performModifications:] + 155
> 	6   UIKit                               0x000000010542983a __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
> 	7   UIKit                               0x000000010542964d -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
> 	8   UIKit                               0x0000000105429933 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 217
> 	9   Foundation                          0x00000001041ea1be -[NSISEngine withBehaviors:performModifications:] + 155
> 	10  UIKit                               0x000000010542983a __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
> 	11  UIKit                               0x000000010542964d -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
> 	12  UIKit                               0x0000000105429933 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 217
> 	13  Foundation                          0x00000001041ea1be -[NSISEngine withBehaviors:performModifications:] + 155
> 	14  UIKit                               0x000000010542983a __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
> 	15  UIKit                               0x000000010542964d -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
> 	16  UIKit                               0x0000000104e22717 __40-[UIView(Hierarchy) layoutBelowIfNeeded]_block_invoke + 39
> 	17  Foundation                          0x00000001041ea1be -[NSISEngine withBehaviors:performModifications:] + 155
> 	18  UIKit                               0x0000000104e22556 -[UIView(Hierarchy) layoutBelowIfNeeded] + 320
> 	19  UIKit                               0x00000001051b7394 -[_UIAlertControllerAnimatedTransitioning animateTransition:] + 470
> 	20  UIKit                               0x0000000104ebca4e __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 1867
> 	21  UIKit                               0x0000000104dd262c _applyBlockToCFArrayCopiedToStack + 314
> 	22  UIKit                               0x0000000104dd24a6 _afterCACommitHandler + 533
> 	23  CoreFoundation                      0x00000001048e7ca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
> 	24  CoreFoundation                      0x00000001048e7c00 __CFRunLoopDoObservers + 368
> 	25  CoreFoundation                      0x00000001048dda33 __CFRunLoopRun + 1123
> 	26  CoreFoundation                      0x00000001048dd366 CFRunLoopRunSpecific + 470
> 	27  GraphicsServices                    0x0000000107f29a3e GSEventRunModal + 161
> 	28  UIKit                               0x0000000104dae900 UIApplicationMain + 1282
> 	29  simpletestapp                       0x0000000104118d3f main + 111
> 	30  libdyld.dylib                       0x0000000106f83145 start + 1
> )
> libc++abi.dylib: terminating with uncaught exception of type NSException