title: NSInvalidArgumentException, Unrec thrown in Monotouch
body: <p>The issue I am facing is thrown on only one device out of several test devices. All devices are iPhone 4s iOS 5.1.1 with another with iOS 6.0.1.</p>
  
  <p>There are several answers to similar questions but none contain both symptoms.</p>
  
  <p>The application has been written in Monotouch.</p>
  
  <p>The symptoms of the issue are</p>
  
  <p>The application will not change orientation on the affected device.
  An NSInvalidArgumentException is thrown when accessing certain views on the affected device.</p>
  
  <p>The full exception is:</p>
  
  <pre>Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UITableViewCell updateConstraintsIfNeeded]: unrecognized selector sent to instance 0x4e07540</pre>
  
  <p>The Stack Trace is</p>
  
  <pre>MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UITableViewCell updateConstraintsIfNeeded]: unrecognized selector sent to instance 0x4c3cc20
    at MonoTouch.UIKit.UIView.UpdateConstraintsIfNeeded () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIView.g.cs:1626
    at XXXXXX.IOS.Dialogs.NewStyledMultilineElement.GetCell (MonoTouch.UIKit.UITableView tv) [0x0000f] in /Users/gavin/Perforce/Jon_PI-151_9051/XXXXXX/XXXXXX/v1.3.1/Mobile/XXXXXX/IOS/XXXXXX.Dialogs/My Work/WorkDetailDialogController.cs:30
    at MonoTouch.Dialog.DialogViewController+Source.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00029] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:340
    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 XXXXXX.IOS.Application.Application.Main (System.String[] args) [0x00000] in /Users/gavin/Perforce/Jon_PI-151_9051/Pall/XXXXXX/v1.3.1/Mobile/XXXXXX/IOS/XXXXXX.Application/Main.cs:28</pre>
  
  <p>The code that is causing the exception is</p>
  
  <pre>public class NewStyledMultilineElement : StyledMultilineElement
  {
      public override UITableViewCell GetCell (UITableView tv)
      {
              UITableViewCell cell = base.GetCell(tv);
              cell.SelectionStyle = UITableViewCellSelectionStyle.None;
              cell.UpdateConstraintsIfNeeded();
              return cell;
      }
  
      public NewStyledMultilineElement(string caption, string value) :base(caption,value)
      {
      }
  }
  </pre>
  
  <p>The line that is throwing the error is 
  cell.UpdateConstraintsIfNeeded();</p>
  
  <p>The version information is</p>
  
  <p>MonoDevelop 3.0.5
  Runtime
    Mono 2.10.9
    GTK 2.24.10
  XCode 4.5.1
  Monotouch 6.0.6</p>
  
  <p>The settings on the affected device have been compaired to other devices that function as expected, with no obvious differences.</p>
  
  <p>It is possible that the symptoms are for different issues. However, this is the only acception that is thrown.</p>
  
  <p>Any help would be greatly appreciated</p>
  
  <p>Further investigation has resolved the issue, temporarily. However the root cause has not been confirmed. The solutions are as follows</p>
  
  <p>To resolve the orientation symptom, the following code was added to the base view controller from which all view controllers are dervied.</p>
  
  <p><code>
      public override bool ShouldAutoRotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
      {
          return true;
      }
  </code></p>
  
  <p>To resolve the NSInvalidArgumentException, StyledMultilineElement have been used instead of the derived class. This issue could be being caused by the GC, but varification of that would be appreciated.</p>
  
  <p>The solutions solve the issue, without identifying the root causes. Any explination of why this is happening on only one device and not all would be helpful.</p>