Bug 41132 - NullReferenceException with Export application supportedInterfaceOrientationsForWindow and IntPtr parameter on Simulators
Summary: NullReferenceException with Export application supportedInterfaceOrientations...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 9.10 (C8)
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-05-17 14:30 UTC by John Miller [MSFT]
Modified: 2016-09-28 04:12 UTC (History)
4 users (show)

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


Attachments
Sample Project (16.67 KB, application/zip)
2016-05-17 19:35 UTC, John Miller [MSFT]
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 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 John Miller [MSFT] 2016-05-17 14:30:09 UTC
**Overview:**

   The following method causes an NRE when running on simulators. 

    Export ("application:supportedInterfaceOrientationsForWindow:")]
		public UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, IntPtr forWindow)
		{
			return UIInterfaceOrientationMask.AllButUpsideDown;
		}

**Steps to Reproduce:**

  Add that method to the AppDelegate.cs file of a blank iOS app and run it on a simulator. 

**Actual Results:**

System.NullReferenceException: Object reference not set to an instance of an object
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/1381/3afb4af5/source/maccore/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/1381/3afb4af5/source/maccore/src/UIKit/UIApplication.cs:63 
  at TestOrientation.Application.Main (System.String[] args) [0x00008] in /Users/johnmiller/Projects/TestOrientation/TestOrientation/Main.cs:12 
2016-05-17 10:17:09.964 TestOrientation[1969:223023] Unhandled managed exception:
Object reference not set to an instance of an object (System.NullReferenceException)
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/1381/3afb4af5/source/maccore/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/1381/3afb4af5/source/maccore/src/UIKit/UIApplication.cs:63 
  at TestOrientation.Application.Main (System.String[] args) [0x00008] in /Users/johnmiller/Projects/TestOrientation/TestOrientation/Main.cs:12 

**Expected Results:**

   No exception.

**Build Date & Platform:**

=== Xamarin Studio Enterprise ===

Version 6.1 (build 817)
Installation UUID: e01c3049-a2d2-4e0a-aad8-afe6fb627c4d
Runtime:
	Mono 4.4.0 (mono-4.4.0-branch/fcf7a6d) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404000148

=== NuGet ===

Version: 3.3.0.0

=== Xamarin.Profiler ===

Not Installed

=== Xamarin.Android ===

Version: 6.1.99.224 (Xamarin Enterprise)
Android SDK: /Users/johnmiller/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 25.1.1
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 7.3 (10183.3)
Build 7D175

=== Xamarin.iOS ===

Version: 9.9.0.719 (Xamarin Enterprise)
Hash: 3afb4af
Branch: master
Build date: 2016-04-24 15:13:41-0400

=== Xamarin.Mac ===

Version: 2.9.0.719 (Xamarin Enterprise)

=== Xamarin Inspector ===

Version: 0.8.1.0
Hash: 95792d1
Branch: master
Build date: Thu May 12 22:20:04 UTC 2016

=== Build Information ===

Release ID: 601000817
Git revision: 2335763551f9db8296b08542035977b899b7f3b7
Build date: 2016-04-25 10:45:36-04
Xamarin addins: 7f8c9ab2a981143a87fbd5adbde3f5890a838fde
Build lane: monodevelop-lion-cycle8-preview

=== Operating System ===

Mac OS X 10.11.2

=== Enabled user installed addins ===

Xamarin Inspector 0.8.1.0

**Additional Information:**

   Running the same on an iPhone 6s did not reproduce the crash. 
   Changing the IntPtr parameter to the type UIWindow stopped the crash. 
   Note* There is a virtual method that can be overridden instead of Exporting this.
Comment 1 Sebastien Pouliot 2016-05-17 19:31:40 UTC
That did not fail for me. It could be an issue with a specific template or some config changes you have on the project. Please attach the failing project to the bug report.
Comment 2 John Miller [MSFT] 2016-05-17 19:35:46 UTC
Created attachment 16023 [details]
Sample Project

Attached a sample project. Run on iOS 9.3 simulator.
Comment 4 Sebastien Pouliot 2016-05-18 19:44:34 UTC
The NRE is an issue with the dynamic registrar (likely a sigsegv). i.e. it does not happen on device [1] and is does not happen using using `--registrar:static` on the simulator.

It also does not happen if you enable the linker, because it removes the *duplicated* selector - and that's the _main_ issue, you should not export the same selector twice and that needs to be fixed in the user code.


[1] even with the linker disabled, however using the dynamic registrar (with the linker disabled) the app will crash with a sigsegv
Comment 7 Rolf Bjarne Kvinge [MSFT] 2016-05-27 16:56:13 UTC
This is an old bug, I can reproduce with both C6 and C7.
Comment 8 Rolf Bjarne Kvinge [MSFT] 2016-05-31 10:11:20 UTC
Fixed: https://github.com/xamarin/xamarin-macios/pull/103
Comment 9 NB 2016-09-26 00:17:58 UTC
Rolf,

So what's the fix? My current workaround is to set up the linker in debug mode.

I checked out the link you provided above and it's a commit into xamarin:master - do I download a newer version of Xamarin Studio or Xamarin.iOS? Here's my setup:

=== Xamarin Studio Community ===
Version 6.0.2 (build 73)
Installation UUID: f923880f-5396-4f6e-b6cc-06a6fd5ed65d
Runtime:
	Mono 4.4.2 (mono-4.4.0-branch-c7sr1/f72fe45) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404020011

=== Apple Developer Tools ===
Xcode 7.3.1 (10188.1)
Build 7D1014

=== Xamarin.iOS ===
Version: 9.8.2.22 (Xamarin Studio Community)
Hash: f37444a
Branch: cycle7-sr1
Build date: 2016-07-28 12:17:02-0400

=== Build Information ===
Release ID: 600020073
Git revision: a6f7a24a9723a2d4f5d33c176615b0d44703ab5b
Build date: 2016-07-26 13:36:15-04
Xamarin addins: f5acb37866a0141bc5ddbe95118f18dae4014568
Build lane: monodevelop-lion-cycle7-sr1

=== Operating System ===
Mac OS X 10.11.6
Darwin xxxx 15.6.0 Darwin Kernel Version 15.6.0
    Thu Jun 23 18:25:34 PDT 2016
    root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64

NB
Comment 10 Rolf Bjarne Kvinge [MSFT] 2016-09-26 08:09:33 UTC
(In reply to NB from comment #9)
> Rolf,
> 
> So what's the fix? My current workaround is to set up the linker in debug
> mode.
> 
> === Xamarin.iOS ===
> Version: 9.8.2.22 (Xamarin Studio Community)

Just upgrade to the latest version of Xamarin.iOS (10.0) and you'll get the fix.
Comment 11 NB 2016-09-28 04:12:06 UTC
Thank you.