Skip to content

ArgumentNullException on UIApplication.SupportedInterfaceOrientationsForWindow #22278

@MichaelLHerman

Description

@MichaelLHerman

Apple platform

iOS

Framework version

net9.0-*

Affected platform version

MAUI 9.0.21

Description

Getting a crash report with the following stack trace

System.ArgumentNullException: ArgumentNull_Generic Arg_ParamName_Name, window
  ?, in NativeHandle NativeObjectExtensions.GetNonNullHandle(INativeObject, string)
  ?, in UIInterfaceOrientationMask UIApplication.SupportedInterfaceOrientationsForWindow(UIWindow)
  ?, in UIInterfaceOrientationMask AppDelegate.GetSupportedInterfaceOrientations(UIApplication application, UIWindow forWindow)
  ?, in UIInterfaceOrientationMask __Registrar_Callbacks__.callback_11_CadabraMobile_iOS_AppDelegate_GetSupportedInterfaceOrientations(IntPtr pobj, IntPtr sel, IntPtr p0, IntPtr p1, IntPtr* exception_gchandle)

Apple marks the window parameter as nullable, but the generated code seems to be doing a null check.

Steps to Reproduce

My app is overriding supportedInterfaceOrientationsForWindow because we disallow rotation on all but one screen, so this can not be hardcoded in the info.plist

        [Export("application:supportedInterfaceOrientationsForWindow:")]
        public UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application,
            UIWindow? forWindow)
        {
            if (forWindow?.WindowScene != null && AllowRotation)
            {
                return UIInterfaceOrientationMask.All;
            }

            return application.SupportedInterfaceOrientationsForWindow(forWindow);
        }

Crash is being reported for iPad Pro (12.9-inch) (3rd generation) running iOS 17.6, app in foreground

Did you find any workaround?

No response

Relevant logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIf an issue is a bug or a pull request a bug fix

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions