Bug 24939 - Exception when accessing LayoutMargins property
Summary: Exception when accessing LayoutMargins property
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.4.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-11-30 18:45 UTC by Cody Beyer (MSFT)
Modified: 2014-12-01 03:22 UTC (History)
2 users (show)

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

TestCase (8.47 KB, application/zip)
2014-11-30 18:45 UTC, Cody Beyer (MSFT)

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 Cody Beyer (MSFT) 2014-11-30 18:45:30 UTC
Created attachment 8910 [details]

### Description 

When accessing the LayoutMargins property in any class that inherits from UI view, an exception is thrown. This occurs only on 7.1, and does not happen on iOS 8

### Test Case


### Steps to Reproduce

1. Open Attached Test Case
2. Deploy to iOS 7.1 Device
3. Click anywhere on screen
4. Notice exception

### Exception Details

Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UIView layoutMargins]: unrecognized selector sent to instance 0x78ce9d20
  at at (wrapper managed-to-native) ObjCRuntime.Messaging:UIEdgeInsets_objc_msgSend_stret (UIKit.UIEdgeInsets&,intptr,intptr)
  at UIKit.UIView.get_LayoutMargins () [0x00083] in /Developer/MonoTouch/Source/monotouch/src/build/native/UIKit/UIView.g.cs:3713
  at CrashExample.CrashExampleViewController.<ViewDidLoad>m__0 () [0x00007] in /Users/codybeyer/Downloads/CrashExample/CrashExampleViewController.cs:45
  at UIKit.UIGestureRecognizer+ParameterlessDispatch.Activated () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIGestureRecognizer.cs:58
  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 CrashExample.Application.Main (System.String[] args) [0x00008] in /Users/codybeyer/Downloads/CrashExample/Main.cs:17

### Version

=== Xamarin Studio ===

Version 5.5.4 (build 15)
Installation UUID: 3e4348fa-e0b3-46a4-8426-58f27e19159e
	Mono 3.10.0 ((detached/92c4884)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000031

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 840a925
Build date: 2014-11-16 21:03:22-0500

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.4    (API level 19)
		4.4.87 (API level 20)
Java SDK: /usr
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 15:32:41-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8

=== Operating System ===

Mac OS X 10.10.1
Darwin Codys-MacBook-Pro.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 1 Rolf Bjarne Kvinge [MSFT] 2014-12-01 03:22:01 UTC
LayoutMargins was introduced in iOS 8, so it's normal that it won't work in any older iOS versions.

If you want to have special iOS 8 code paths, you can check the iOS version at runtime: http://stackoverflow.com/a/8311516/183422