Skip to content

[release/11.0.1xx-preview7] Avoid null TypedBinding source during ancestor detach - #37095

Merged
kubaflo merged 1 commit into
release/11.0.1xx-preview7from
fix/typedbinding-relative-source-null
Aug 4, 2026
Merged

[release/11.0.1xx-preview7] Avoid null TypedBinding source during ancestor detach#37095
kubaflo merged 1 commit into
release/11.0.1xx-preview7from
fix/typedbinding-relative-source-null

Conversation

@PureWeen

@PureWeen PureWeen commented Aug 4, 2026

Copy link
Copy Markdown
Member

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!

Root Cause

TypedBinding.ApplyCore caches a successful TSource type check. Relative source ancestor bindings can temporarily resolve to null when an item is detached or recycled, but the cached result remained true. This caused the generated binding getter to be invoked with a null source, producing a first-chance NullReferenceException that was swallowed by the binding engine but surfaced in the debugger.

This became visible in Preview 7 after #34408 began compiling RelativeSource AncestorType bindings into TypedBinding instances.

Description of Change

Do not reuse the cached successful source type result when the current source is null. This skips subscriptions and getter invocation during the transient detach state while preserving the cached result when the ancestor is resolved again.

Add a regression test that detaches a FindAncestorBindingContext target and verifies its typed getter is never invoked with a null source.

Issues Fixed

Test Coverage

  • RelativeSourceBindingTests

Relative source bindings can temporarily resolve to null while items are detached or recycled. Do not reuse the cached successful source type check for that transient null source, preventing generated getters from receiving null.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 74d6abf7-c466-4cff-aaaf-f990c083a7af
Copilot AI review requested due to automatic review settings August 4, 2026 17:50
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool August 4, 2026 17:50 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37095

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37095"

@PureWeen
PureWeen temporarily deployed to copilot-pat-pool August 4, 2026 17:50 — with GitHub Actions Inactive
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@PureWeen
PureWeen temporarily deployed to copilot-pat-pool August 4, 2026 17:54 — with GitHub Actions Inactive
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool August 4, 2026 17:54 — with GitHub Actions Inactive
@github-actions github-actions Bot added the area-xaml XAML, CSS, Triggers, Behaviors label Aug 4, 2026
@PureWeen
PureWeen temporarily deployed to copilot-pat-pool August 4, 2026 17:55 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the TypedBinding engine to avoid invoking typed binding getters (and related subscription logic) when a relative-source binding temporarily resolves to a null source during ancestor detach/recycle scenarios. It also adds a unit test to prevent regressions for FindAncestorBindingContext typed bindings.

Changes:

  • Update TypedBinding.ApplyCore to avoid reusing a cached “is TSource” result when the current source object is null.
  • Add a regression unit test ensuring a typed getter is not invoked with a null source when an ancestor binding context becomes temporarily unresolved.
Show a summary per file
File Description
src/Controls/src/Core/TypedBinding.cs Prevents cached typed-source checks from being applied when the current resolved source is null, avoiding getter invocation during transient detach states.
src/Controls/tests/Core.UnitTests/RelativeSourceBindingTests.cs Adds a regression test covering FindAncestorBindingContext typed binding behavior during detach to ensure the getter isn’t called with a null source.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@kubaflo
kubaflo merged commit dee83ed into release/11.0.1xx-preview7 Aug 4, 2026
11 of 20 checks passed
@kubaflo
kubaflo deleted the fix/typedbinding-relative-source-null branch August 4, 2026 17:56
@github-actions github-actions Bot added this to the .NET 11.0-preview7 milestone Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-xaml XAML, CSS, Triggers, Behaviors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants