Skip to content

Fix typed bindings invoking generated getters with missing ancestor sources - #39470

Merged
kubaflo merged 3 commits into
inflight/currentfrom
jfversluis-issue-38667-fix
Oct 20, 2026
Merged

kubaflo merged 3 commits into
inflight/currentfrom
jfversluis-issue-38667-fix

Conversation

@jfversluis

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!

Description of Change

Recheck source compatibility on every TypedBinding.ApplyCore invocation instead of caching it alongside the target property's default value.

During Windows CollectionView recycling, a template can temporarily lose its ancestor. RelativeBindingSource intentionally applies a null source until the ancestor becomes available again. The previously cached successful type check allowed the null source through to SourceGen getters such as source => (source.UseCommand, true), causing a first-chance NullReferenceException. The reverse transition could also leave a binding using a cached unsuccessful check after a compatible source became available.

This change prevents getter invocation for null or incompatible sources, restores binding values when a compatible source returns, and deduplicates consecutive source-type mismatch diagnostics. It does not retain the source strongly or change the public API. The fix is in shared binding code; Windows is the runtime-validated platform, not an exclusive scope claim.

Regression tests count getter invocations, so they detect the exception even when the binding engine catches it. Coverage includes valid/null/incompatible/valid transitions, fallback values, initial incompatible-source recovery, and OneWay, OneTime, and TwoWay modes.

Verification

  • Reproduced with the public sample from SourceGen compiled RelativeSource AncestorType binding on Windows intermittently invokes its generated getter with a null source #38667 using Microsoft.Maui.Controls 10.0.110, SourceGen, and Windows ARM64.
  • Added an instrumented runtime harness in a local scratch copy of the sample: incremental animated scrolling, large scrolling jumps, dynamic-resource replacement, ItemsSource reset, and ancestor detach/reattach.
  • Before: 6,094 matching first-chance exceptions in generated command getters. These were caught by the binding engine; the standalone process did not terminate.
  • After: zero matching exceptions in two complete five-scenario runs. Confirmed the running app loaded the source-built Windows Controls assembly, and a real item-command click still updated the UI.
  • Regression cases failed against the unchanged implementation and pass with the fix. The final five regression cases pass locally.
  • Broader TypedBinding tests: 115 passed, 2 skipped, and one FailToConvert failure also reproduced on the unchanged baseline.
  • Runtime harness/logs are local investigation artifacts, not additions to the repository. Android and iOS runtime verification has not been performed.

Issues Fixed

Fixes #38667

dotnet-maestro Bot and others added 3 commits October 19, 2026 12:36
This pull request updates the following dependencies

[marker]: <> (Begin:a71c12d9-5aa4-4b46-e2d6-08da0cf8cd95)
## From https://github.com/dotnet/xharness
- **Subscription**:
[a71c12d9-5aa4-4b46-e2d6-08da0cf8cd95](https://maestro.dot.net/subscriptions?search=a71c12d9-5aa4-4b46-e2d6-08da0cf8cd95)
- **Build**:
[20261017.1](https://dev.azure.com/dnceng/internal/_build/results?buildId=3108278)
([337047](https://maestro.dot.net/channel/2/github:dotnet:xharness/build/337047))
- **Date Produced**: October 17, 2026 7:49:04 PM UTC
- **Commit**:
[38ed2081279c3f4dee81c933aaa9721b50a44adb](dotnet/xharness@38ed208)
- **Branch**: [main](https://github.com/dotnet/xharness/tree/main)

[DependencyUpdate]: <> (Begin)

- **Dependency Updates**:
  - From [11.0.0-prerelease.26506.1 to 11.0.0-prerelease.26517.1][1]
     - Microsoft.DotNet.XHarness.CLI
     - Microsoft.DotNet.XHarness.TestRunners.Common
     - Microsoft.DotNet.XHarness.TestRunners.Xunit

[1]: dotnet/xharness@91708f0...38ed208

[DependencyUpdate]: <> (End)


[marker]: <> (End:a71c12d9-5aa4-4b46-e2d6-08da0cf8cd95)

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
<!-- 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!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

Preserve the identity metadata required by Memory Leak Fixer's GitHub
integrity guard.

The [reported
run](https://github.com/dotnet/maui/actions/runs/39183685618) already
loaded `min-integrity: approved` and `trusted-users:
["github-actions[bot]"]`, including the trust correction from #39332.
However, its MCP `list_issues` and `search_issues` calls requested
projected `fields` without `user` or `author_association`. Field
selection happens before guard evaluation, so the guard could not
recognize the scanner's trusted bot identity. Issue #37848 was
consequently filtered at `unapproved` integrity.

The workflow now explicitly requires all MCP issue/PR list and search
calls to omit `fields`, retain the original metadata through the guard,
and reduce only permitted results locally. This covers review-response
discovery, leak selection, deduplication, and attempt caps. Queries must
scope to workflow candidates, and filtered/failed evidence must stop
publication rather than look like an empty or complete inventory.

Approved integrity, bot trust, permissions, firewall, threat detection,
safe-output restrictions, and all action/container/model pins remain
unchanged. The regenerated lock changes only the prompt body hash. The
fix does not permit raw-REST retries, alternate-tool access to withheld
content, or a lower integrity threshold.

Validation:

- `gh aw compile leak-fixer --strict --shellcheck --no-check-update
--json` - passed with no errors or warnings; retained the original
action/container pins using the local compiler pin cache and restored
that cache afterward.
- `gh aw compile leak-fixer --strict --staged --no-emit
--no-check-update --json` - passed with no errors or warnings.
- `git diff --check` - passed.
- `actionlint -format '{{json .}}'
.github/workflows/leak-fixer.lock.yml` - reports the same four
diagnostics as the untouched base (two unsupported generated
`concurrency.queue` keys, existing SC2129 style advice, and an existing
`github.aw` import expression). No new diagnostics.
- Read-only GPT-6.1 Sol security review of the final source/lock change
- passed; no confirmed vulnerabilities.

No pipeline tests were added. `--dry-run` is unavailable in the pinned
gh-aw v0.86.2 compiler; the commands above are configuration checks, not
a live dry-run. No agent workflow was dispatched, and hosted recovery
remains unverified until the revised workflow runs.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #39447

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: aa3864d1-3642-4dd3-a02b-90c0ed19eb6d
Recheck source compatibility on every binding application so recycled ancestor bindings never invoke generated getters with null or incompatible sources. Cover recovery and fallback behavior across binding modes.

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

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 -- 39470

Or

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

@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.

@MauiBot

MauiBot commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@jfversluis — existing-test verification for commit 5577f2e8.

Result FAILED Platform Android Commit 5577f2e8


🧪 Gate analysis — click to expand

❌ Failed. The selected tests did not meet the expected outcomes. Inspect the evidence before changing the test or fix.

🧪 Unit tests
Test group Without fix With fix
TypedBindingUnitTests ✅ Failed as expected (103s) ❌ Failed (102s)
Execution log excerpts

Without fix TypedBindingUnitTests

     at Microsoft.Maui.Controls.Core.UnitTests.TypedBindingUnitTests.TypedBinding_DoesNotInvokeGetter_WhenSourceBecomesNullOrWrongType(BindingMode mode) in /_/src/Controls/tests/Core.UnitTests/TypedBindingUnitTests.cs:line 1885
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at InvokeStub_TypedBindingUnitTests.TypedBinding_DoesNotInvokeGetter_WhenSourceBecomesNullOrWrongType(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at Microsoft.Maui.Controls.Core.UnitTests.TypedBindingUnitTests.FailToConvert() in /_/src/Controls/tests/Core.UnitTests/TypedBindingUnitTests.cs:line 1300
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
     at Microsoft.Maui.Controls.Core.UnitTests.TypedBindingUnitTests.TypedBinding_RecoversFromInitialWrongTypeContext() in /_/src/Controls/tests/Core.UnitTests/TypedBindingUnitTests.cs:line 1957

With fix TypedBindingUnitTests

     at Microsoft.Maui.Controls.Core.UnitTests.TypedBindingUnitTests.FailToConvert() in /_/src/Controls/tests/Core.UnitTests/TypedBindingUnitTests.cs:line 1300
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

PR head: 5577f2e8.

Without-fix baseline: b36d97a9.

@MauiBot MauiBot added s/agent-gate-failed AI could not verify tests catch the bug and removed s/agent-review-in-progress AI review is currently running for this PR labels Oct 19, 2026
@ahmed-abdelrazek

Copy link
Copy Markdown

the pr targets the new .net 11 not 10 but i can confirm that it fixed the issue @jfversluis

@jfversluis
jfversluis marked this pull request as ready for review October 19, 2026 18:41
@jfversluis
jfversluis requested review from StephaneDelcroix and a balanced review from Copilot October 19, 2026 18:41

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.

🔵 Needs a closer look

The shared binding-engine change needs human review because current CI results and reported runtime validation were not independently verified.

No open issues 🎉

What changed in this PR

Fixes #38667 in shared typed-binding code by rechecking source compatibility before invoking generated getters.

Changes:

  • Replaces cached source-type checks with validation on every application.
  • Deduplicates consecutive source-type mismatch diagnostics.
  • Adds regression coverage for source transitions, fallback values, recovery, and three binding modes.
File Description
src/​Controls/​tests/​Core.UnitTests/​TypedBindingUnitTests.cs Adds getter-invocation and source-recovery regression tests.
src/​Controls/​src/​Core/​TypedBinding.cs Revalidates sources and tracks repeated mismatch diagnostics.

Review effort: Balanced

@kubaflo

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 20, 2026
@kubaflo

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

/review gate was not started: another review or Gate is already running for this PR.

This command is not queued. Submit it again after the current run finishes.

@kubaflo

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Tests Failure Analysis

@jfversluis — test-failure analysis for commit 5577f2e.

Scope CI failures Commit 5577f2e


🧪 CI Analysis — click to expand
📊 maui-pr

No failures found.


🧪 maui-pr-devicetests
  • 🟡 Needs human investigation - iOS Mono TapGestureRecognizer leak: a Label survives collection; five target runs lack equivalent verified Helix coverage.
  • 🟡 Needs human investigation - iOS Mono General work item: reported crash/incomplete execution; inspect the termination diagnostic, not merely the downstream PowerShell exit.

🧪 maui-pr-uitests

Target matches below reproduce the same platform/reason on main without this binding fix.

Insufficient data - UI evidence: only 100/446 failed-result records captured; canceled Shell/Label/Layout legs and bounded target samples prevent exhaustive attribution.


🧭 Follow-up — actions and refresh

Next action: Restore complete results and first-crash diagnostics; compare unresolved cases with/without the binding fix.

Maintainers: comment /review tests to refresh this report.

@kubaflo
kubaflo changed the base branch from main to inflight/current October 20, 2026 22:59
@kubaflo
kubaflo merged commit 5c6c796 into inflight/current Oct 20, 2026
194 of 207 checks passed
@kubaflo
kubaflo deleted the jfversluis-issue-38667-fix branch October 20, 2026 22:59
kubaflo pushed a commit that referenced this pull request Oct 21, 2026
…ources (#39470)

<!-- 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!

Recheck source compatibility on every `TypedBinding.ApplyCore`
invocation instead of caching it alongside the target property's default
value.

During Windows CollectionView recycling, a template can temporarily lose
its ancestor. `RelativeBindingSource` intentionally applies a null
source until the ancestor becomes available again. The previously cached
successful type check allowed the null source through to SourceGen
getters such as `source => (source.UseCommand, true)`, causing a
first-chance `NullReferenceException`. The reverse transition could also
leave a binding using a cached unsuccessful check after a compatible
source became available.

This change prevents getter invocation for null or incompatible sources,
restores binding values when a compatible source returns, and
deduplicates consecutive source-type mismatch diagnostics. It does not
retain the source strongly or change the public API. The fix is in
shared binding code; Windows is the runtime-validated platform, not an
exclusive scope claim.

Regression tests count getter invocations, so they detect the exception
even when the binding engine catches it. Coverage includes
valid/null/incompatible/valid transitions, fallback values, initial
incompatible-source recovery, and OneWay, OneTime, and TwoWay modes.

- Reproduced with the public sample from #38667 using
Microsoft.Maui.Controls 10.0.110, SourceGen, and Windows ARM64.
- Added an instrumented runtime harness in a local scratch copy of the
sample: incremental animated scrolling, large scrolling jumps,
dynamic-resource replacement, ItemsSource reset, and ancestor
detach/reattach.
- Before: 6,094 matching first-chance exceptions in generated command
getters. These were caught by the binding engine; the standalone process
did not terminate.
- After: zero matching exceptions in two complete five-scenario runs.
Confirmed the running app loaded the source-built Windows Controls
assembly, and a real item-command click still updated the UI.
- Regression cases failed against the unchanged implementation and pass
with the fix. The final five regression cases pass locally.
- Broader TypedBinding tests: 115 passed, 2 skipped, and one
`FailToConvert` failure also reproduced on the unchanged baseline.
- Runtime harness/logs are local investigation artifacts, not additions
to the repository. Android and iOS runtime verification has not been
performed.

Fixes #38667

---------
kubaflo pushed a commit that referenced this pull request Oct 25, 2026
…ources (#39470)

<!-- 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!

Recheck source compatibility on every `TypedBinding.ApplyCore`
invocation instead of caching it alongside the target property's default
value.

During Windows CollectionView recycling, a template can temporarily lose
its ancestor. `RelativeBindingSource` intentionally applies a null
source until the ancestor becomes available again. The previously cached
successful type check allowed the null source through to SourceGen
getters such as `source => (source.UseCommand, true)`, causing a
first-chance `NullReferenceException`. The reverse transition could also
leave a binding using a cached unsuccessful check after a compatible
source became available.

This change prevents getter invocation for null or incompatible sources,
restores binding values when a compatible source returns, and
deduplicates consecutive source-type mismatch diagnostics. It does not
retain the source strongly or change the public API. The fix is in
shared binding code; Windows is the runtime-validated platform, not an
exclusive scope claim.

Regression tests count getter invocations, so they detect the exception
even when the binding engine catches it. Coverage includes
valid/null/incompatible/valid transitions, fallback values, initial
incompatible-source recovery, and OneWay, OneTime, and TwoWay modes.

- Reproduced with the public sample from #38667 using
Microsoft.Maui.Controls 10.0.110, SourceGen, and Windows ARM64.
- Added an instrumented runtime harness in a local scratch copy of the
sample: incremental animated scrolling, large scrolling jumps,
dynamic-resource replacement, ItemsSource reset, and ancestor
detach/reattach.
- Before: 6,094 matching first-chance exceptions in generated command
getters. These were caught by the binding engine; the standalone process
did not terminate.
- After: zero matching exceptions in two complete five-scenario runs.
Confirmed the running app loaded the source-built Windows Controls
assembly, and a real item-command click still updated the UI.
- Regression cases failed against the unchanged implementation and pass
with the fix. The final five regression cases pass locally.
- Broader TypedBinding tests: 115 passed, 2 skipped, and one
`FailToConvert` failure also reproduced on the unchanged baseline.
- Runtime harness/logs are local investigation artifacts, not additions
to the repository. Android and iOS runtime verification has not been
performed.

Fixes #38667

---------
kubaflo pushed a commit that referenced this pull request Oct 26, 2026
…ources (#39470)

<!-- 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!

Recheck source compatibility on every `TypedBinding.ApplyCore`
invocation instead of caching it alongside the target property's default
value.

During Windows CollectionView recycling, a template can temporarily lose
its ancestor. `RelativeBindingSource` intentionally applies a null
source until the ancestor becomes available again. The previously cached
successful type check allowed the null source through to SourceGen
getters such as `source => (source.UseCommand, true)`, causing a
first-chance `NullReferenceException`. The reverse transition could also
leave a binding using a cached unsuccessful check after a compatible
source became available.

This change prevents getter invocation for null or incompatible sources,
restores binding values when a compatible source returns, and
deduplicates consecutive source-type mismatch diagnostics. It does not
retain the source strongly or change the public API. The fix is in
shared binding code; Windows is the runtime-validated platform, not an
exclusive scope claim.

Regression tests count getter invocations, so they detect the exception
even when the binding engine catches it. Coverage includes
valid/null/incompatible/valid transitions, fallback values, initial
incompatible-source recovery, and OneWay, OneTime, and TwoWay modes.

- Reproduced with the public sample from #38667 using
Microsoft.Maui.Controls 10.0.110, SourceGen, and Windows ARM64.
- Added an instrumented runtime harness in a local scratch copy of the
sample: incremental animated scrolling, large scrolling jumps,
dynamic-resource replacement, ItemsSource reset, and ancestor
detach/reattach.
- Before: 6,094 matching first-chance exceptions in generated command
getters. These were caught by the binding engine; the standalone process
did not terminate.
- After: zero matching exceptions in two complete five-scenario runs.
Confirmed the running app loaded the source-built Windows Controls
assembly, and a real item-command click still updated the UI.
- Regression cases failed against the unchanged implementation and pass
with the fix. The final five regression cases pass locally.
- Broader TypedBinding tests: 115 passed, 2 skipped, and one
`FailToConvert` failure also reproduced on the unchanged baseline.
- Runtime harness/logs are local investigation artifacts, not additions
to the repository. Android and iOS runtime verification has not been
performed.

Fixes #38667

---------
github-actions Bot pushed a commit that referenced this pull request Oct 28, 2026
…ources (#39470)

<!-- 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!

Recheck source compatibility on every `TypedBinding.ApplyCore`
invocation instead of caching it alongside the target property's default
value.

During Windows CollectionView recycling, a template can temporarily lose
its ancestor. `RelativeBindingSource` intentionally applies a null
source until the ancestor becomes available again. The previously cached
successful type check allowed the null source through to SourceGen
getters such as `source => (source.UseCommand, true)`, causing a
first-chance `NullReferenceException`. The reverse transition could also
leave a binding using a cached unsuccessful check after a compatible
source became available.

This change prevents getter invocation for null or incompatible sources,
restores binding values when a compatible source returns, and
deduplicates consecutive source-type mismatch diagnostics. It does not
retain the source strongly or change the public API. The fix is in
shared binding code; Windows is the runtime-validated platform, not an
exclusive scope claim.

Regression tests count getter invocations, so they detect the exception
even when the binding engine catches it. Coverage includes
valid/null/incompatible/valid transitions, fallback values, initial
incompatible-source recovery, and OneWay, OneTime, and TwoWay modes.

- Reproduced with the public sample from #38667 using
Microsoft.Maui.Controls 10.0.110, SourceGen, and Windows ARM64.
- Added an instrumented runtime harness in a local scratch copy of the
sample: incremental animated scrolling, large scrolling jumps,
dynamic-resource replacement, ItemsSource reset, and ancestor
detach/reattach.
- Before: 6,094 matching first-chance exceptions in generated command
getters. These were caught by the binding engine; the standalone process
did not terminate.
- After: zero matching exceptions in two complete five-scenario runs.
Confirmed the running app loaded the source-built Windows Controls
assembly, and a real item-command click still updated the UI.
- Regression cases failed against the unchanged implementation and pass
with the fix. The final five regression cases pass locally.
- Broader TypedBinding tests: 115 passed, 2 skipped, and one
`FailToConvert` failure also reproduced on the unchanged baseline.
- Runtime harness/logs are local investigation artifacts, not additions
to the repository. Android and iOS runtime verification has not been
performed.

Fixes #38667

---------
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 20, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 5577f2e8 Deployed Oct 19, 2026 by jfversluis via conclusion #2395
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

s/agent-gate-failed AI could not verify tests catch the bug s/agent-review-in-progress AI review is currently running for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SourceGen compiled RelativeSource AncestorType binding on Windows intermittently invokes its generated getter with a null source

6 participants