Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 17, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

On iPadOS 26.1+ with windowed apps < 667pt width, TabbedPage crashes during initialization with NullReferenceException in TabbedRenderer.get_Element().

Root cause: iOS 26.1+ calls ViewDidLayoutSubviews() during UITabBarController base constructor execution in narrow viewports. This occurs before the derived TabbedRenderer constructor body runs, leaving _viewHandlerWrapper uninitialized when Element property is accessed.

Fix: Add null-conditional operator to Element property getter:

- public VisualElement Element => _viewHandlerWrapper.Element ?? _element?.GetTargetOrDefault();
+ public VisualElement Element => _viewHandlerWrapper?.Element ?? _element?.GetTargetOrDefault();

The existing if (Element is IView view) pattern in ViewDidLayoutSubviews() already handles null safely.

Issues Fixed

Fixes #32661

Original prompt

This section details on the original issue you should resolve

<issue_title>TabbedPage crashes on iPadOS 26.1 with windowed applications in narrow viewports</issue_title>
<issue_description>### Description

When a .NET MAUI application initializes a TabbedPage with its default handler (Handlers.Compatibility.TabbedRenderer) in a windowed application with a width of 667 points or less on iPadOS 26.1, the application crashes with a null reference exception deep within the framework code. When the window width exceeds 667 points, the TabbedPage and its contents load and display properly.

Width < 667 (Non-working Scenario) Image Image
Width > 667 (Working Scenario) Image Image

Stack Trace

at Microsoft.Maui.Controls.Handlers.Compatibility.TabbedRenderer.get_Element()
at Microsoft.Maui.Controls.Handlers.Compatibility.TabbedRenderer.ViewDidLayoutSubviews()
at ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper(IntPtr receiver, IntPtr selector)
at UIKit.UITabBarController..ctor()
at Microsoft.Maui.Controls.Handlers.Compatibility.TabbedRenderer..ctor()
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.Maui.Hosting.Internal.MauiFactory.CreateInstance(ServiceDescriptor item)
at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType)
at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory.GetHandler(Type type)
at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.CreateViewControllerForPage(Page page)
at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.<OnPushAsync>d__60.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.OnPushAsync(Page page, Boolean animated)
at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.PushPageAsync(Page page, Boolean animated)
at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.OnPushRequested(Object sender, NavigationRequestedEventArgs e)
at Microsoft.Maui.Controls.NavigationPage.<PushAsyncInner>d__136.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.Maui.Controls.NavigationPage.PushAsyncInner(Page page, Boolean animated)
at Microsoft.Maui.Controls.NavigationPage.<PushAsync>d__67.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.Maui.Controls.NavigationPage.PushAsync(Page page, Boolean animated)
at Microsoft.Maui.Controls.NavigationPage.NavigationImpl.OnPushAsync(Page root, Boolean animated)
at Microsoft.Maui.Controls.Internals.NavigationProxy.PushAsync(Page root, Boolean animated)
at Microsoft.Maui.Controls.Internals.NavigationProxy.PushAsync(Page root)
at MauiWindowingTest.IntermPageViewModel.<>c.<.ctor>b__17_0() in C:\REDACTED\MauiWindowingTest\IntermPage.xaml.cs:line 47
at Microsoft.Maui.Controls.Command.<>c__DisplayClass4_0.<.ctor>b__0(Object o)
at Microsoft.Maui.Controls.Command.Execute(Object parameter)
at Microsoft.Maui.Controls.ButtonElement.ElementClicked(VisualElement visualElement, IButtonElement ButtonElementManager)
at Microsoft.Maui.Controls.Button.SendClicked()
at Microsoft.Maui.Controls.Button.Microsoft.Maui.IButton.Clicked()
at Microsoft.Maui.Handlers.ButtonHandler.ButtonEventProxy.OnButtonTouchUpInside(Object sender, EventArgs e)
at UIKit.UIControlEventProxy.Activated()
at UIKit.UIApplicat...

</details>

- Fixes dotnet/maui#32661

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI changed the title [WIP] Fix TabbedPage crashes on iPadOS 26.1 in narrow viewports Fix TabbedPage crash on iPadOS 18+ with narrow viewports Nov 17, 2025
Copilot AI requested a review from jfversluis November 17, 2025 10:15
@jfversluis
Copy link
Member

/azp run MAUI-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis jfversluis changed the title Fix TabbedPage crash on iPadOS 18+ with narrow viewports Fix TabbedPage crash on iPadOS 26+ with narrow viewports Nov 17, 2025
@Emtiaz-Tafsir
Copy link

Fix confirmed #32661 (comment)

@jfversluis jfversluis marked this pull request as ready for review November 18, 2025 08:22
Copilot AI review requested due to automatic review settings November 18, 2025 08:22
@jfversluis
Copy link
Member

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a crash in TabbedPage on iPadOS 26.1+ when apps use narrow viewports (< 667 points width). The crash occurs due to iOS calling ViewDidLayoutSubviews() during the UITabBarController base constructor, before the derived class TabbedRenderer has initialized its _viewHandlerWrapper field.

Key Changes:

  • Added null-conditional operator to Element property getter to handle early lifecycle calls
  • Added explanatory comment documenting the iOS version and viewport width condition

@PureWeen PureWeen added this to the .NET 10.0 SR1.1 milestone Nov 18, 2025
@PureWeen PureWeen moved this from Todo to Ready To Review in MAUI SDK Ongoing Nov 18, 2025
@PureWeen
Copy link
Member

/backport to release/10.0.1xx-sr1

@github-actions
Copy link
Contributor

Started backporting to release/10.0.1xx-sr1 (link to workflow run)

@PureWeen
Copy link
Member

/rebase

@github-actions
Copy link
Contributor

@PureWeen backporting to release/10.0.1xx-sr1 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Patch format detection failed.
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

Copilot AI and others added 2 commits November 18, 2025 15:21
Add null-conditional operator to Element property getter to handle early ViewDidLayoutSubviews callback

Co-authored-by: jfversluis <[email protected]>
@github-actions github-actions bot force-pushed the copilot/fix-tabbedpage-crash-ipados branch from 00a8216 to 0a76a68 Compare November 18, 2025 15:21
@PureWeen
Copy link
Member

/backport to release/10.0.1xx-sr1

@PureWeen
Copy link
Member

/azp run

@github-actions
Copy link
Contributor

Started backporting to release/10.0.1xx-sr1 (link to workflow run)

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@github-actions
Copy link
Contributor

@PureWeen backporting to release/10.0.1xx-sr1 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Patch format detection failed.
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

jfversluis added a commit that referenced this pull request Nov 19, 2025
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

On iPadOS 26.1+, `TabbedPage` crashes with `NullReferenceException` in
windowed apps < 667pt width. iOS 26.1 introduced early
`ViewDidLayoutSubviews()` calls during `UITabBarController` base
constructor execution for narrow viewports, before `_viewHandlerWrapper`
initialization completes.

**Fix:** Add null-conditional operator to `Element` property getter:

```diff
- public VisualElement Element => _viewHandlerWrapper.Element ?? _element?.GetTargetOrDefault();
+ public VisualElement Element => _viewHandlerWrapper?.Element ?? _element?.GetTargetOrDefault();
```

The existing `if (Element is IView view)` guard in
`ViewDidLayoutSubviews()` handles null safely.

### Issues Fixed

Fixes #32661

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> Backport #32662


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
@jfversluis jfversluis merged commit 9390265 into main Nov 19, 2025
155 of 164 checks passed
@jfversluis jfversluis deleted the copilot/fix-tabbedpage-crash-ipados branch November 19, 2025 16:06
@github-project-automation github-project-automation bot moved this from Ready To Review to Done in MAUI SDK Ongoing Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

TabbedPage crashes on iPadOS 26.1 with windowed applications in narrow viewports

4 participants