Repository navigation
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40199Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40199" |
|
Hey there @@Oxymoron290! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This comment has been minimized.
This comment has been minimized.
|
Hey there @Oxymoron290! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This comment has been minimized.
This comment has been minimized.
|
/rebase |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. No interpretable test-group summary was produced. No additional test execution is inferred. Setup did not capture a verified PR head; no commit is claimed as tested. No immutable without-fix baseline was prepared. |
There was a problem hiding this comment.
Expert Review — 0 findings
Reviewed commit 0088a35.
4145855
into
dotnet:candidate/11.0.1xx-sr2
<!-- 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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes #40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes #40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes #40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes #40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
|
Could this fix be considered for the next available .NET 10 servicing release? The crash reproduces with MAUI 10.0.100 and 10.0.110. The candidate fix and regression were previously validated against 10.0.110, and the net11 regression fails without the fix and passes with it. The change prevents command notifications to collected controls and adds one weak reference per subscription. Customer-app validation and Android runtime validation remain outstanding. Could a maintainer apply |
…0339) <!-- 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 Backport of #40199 to `release/10.0.1xx-sr14` (SR14 / 10.0.140, tracking PR #40222), as requested in #40199 (comment). `WeakCommandSubscription.CommandCanExecuteSubscription` now keeps a `WeakReference<BindableObject>` to the target and resolves it before invoking the handler. A `DependentHandle` can still expose a finalization-reachable target after its binding weak references have been finalized; notifying that target caused the crash. When the target is gone, the subscription disposes itself. Cost: one weak reference per subscription. Clean cherry-pick of 0088a35 (no conflicts). Validation on the SR14 base (72615b7) with SDK 10.0.113-servicing.26454.107 (from `global.json`), `net10.0`, mobile TFMs disabled: - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~CommandTests|FullyQualifiedName~WeakCommand"` → passed 48/48 - `CanExecuteDoesNotRefreshCollectedButtonBindings` with production change reverted → failed 3/3; restored → passed 3/3 - Full `Controls.Core.UnitTests` → passed 5966, skipped 30, failed 0 Not run: customer-app validation and Android/iOS runtime validation. ### Issues Fixed Fixes #40198 Co-authored-by: Timothy Sturm <timothysturm@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes #40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes #40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes #40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes #40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes #40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes #40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.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! ### Target Branch - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). - `net11`: .NET 11 servicing fix for review. ### Description of Change When a command outlives a button, the subscription's `DependentHandle` can expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causing `Handle is not initialized`. Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing `DependentHandle` to preserve the handler's lifetime while the object is live. This adds one weak reference per subscription. Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises `CanExecuteChanged`, and verifies that a live button still disables and re-enables. The gate is bounded and released in `finally`. ### Validation - On the `net11` base, the new regression fails without this change with `InvalidOperationException: Handle is not initialized` from `WeakReference<T>.SetTarget`, and passes with the change. - Targeted `CommandTests`, `ButtonUnitTest`, and `TypedBindingUnitTests` on Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excluded `TypedBindingUnitTests.FailToConvert`, which also failed on the unmodified .NET 10 source in earlier local testing. - The standalone .NET 10 reproduction and Windows host also reproduce the reported exception without the fix. Testing used simulated button clicks, not pointer automation. - Formatted the modified files with `dotnet format whitespace`; `git diff --check` passes. The original weak-subscription implementation was introduced by dotnet#29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior. ### Issues Fixed Fixes dotnet#40198 Copilot-Session: 41443241-c376-48d0-b685-7cfa647534be Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
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!
Target Branch
net11: .NET 11 servicing fix for review.Description of Change
When a command outlives a button, the subscription's
DependentHandlecan expose the button while it is finalization-reachable even after the button's short weak reference has cleared. Notifying that button can reapply its compiled command parameter binding after the binding's weak-reference handle has been released, causingHandle is not initialized.Keep a short weak reference to the bindable object in the subscription proxy and resolve it before accessing the dependent handler. If the short reference has cleared, dispose the subscription instead of notifying the abandoned object. Retain the existing
DependentHandleto preserve the handler's lifetime while the object is live. This adds one weak reference per subscription.Add a regression test that delays finalizer processing, collects an abandoned button with a null compiled command-parameter binding, raises
CanExecuteChanged, and verifies that a live button still disables and re-enables. The gate is bounded and released infinally.Validation
net11base, the new regression fails without this change withInvalidOperationException: Handle is not initializedfromWeakReference<T>.SetTarget, and passes with the change.CommandTests,ButtonUnitTest, andTypedBindingUnitTestson Windows ARM64 with the .NET 11 SDK: 251 passed, 2 skipped. The selection excludedTypedBindingUnitTests.FailToConvert, which also failed on the unmodified .NET 10 source in earlier local testing.dotnet format whitespace;git diff --checkpasses.The original weak-subscription implementation was introduced by #29837. A search found no open PR for this exact exception; this change addresses the stale-callback lifetime window rather than modifying that PR's command-retention behavior.
Issues Fixed
Fixes #40198