Repository navigation
[inflight] Fix netstandard build break: ReferenceEqualityComparer in GradientBrush - #36808
Conversation
…GradientBrush GradientBrush (#36746) keyed its subscription ref-count dictionary with System.Collections.Generic.ReferenceEqualityComparer.Instance, which is .NET 5+ only. Controls.Core also targets netstandard2.0/2.1, so the shared build fails: src/Controls/src/Core/GradientBrush.cs(13,71): error CS0122: 'ReferenceEqualityComparer' is inaccessible due to its protection level Replace it with a small self-contained reference-identity comparer that works on every TFM (equality by object reference, hash from RuntimeHelpers.GetHashCode), preserving the leak fix's exact semantics. The other ReferenceEqualityComparer uses (ShellRenderer, MapHandler) are in platform files that only compile for .NET TFMs, so they are unaffected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
AI Review Summary
🗂️ Review Sessions — click to expand🚦 Gate — Test Before & After FixGate Result:
|
| Category | Tests | Snapshot diffs |
|---|---|---|
Brush |
36/36 ✓ | — |
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs) |
📋 Pre-Flight — Context & Validation
Issue: #36808 - [inflight] Fix netstandard build break: ReferenceEqualityComparer in GradientBrush
PR: #36808 - [inflight] Fix netstandard build break: ReferenceEqualityComparer in GradientBrush
Platforms Affected: shared Controls.Core (netstandard2.0, netstandard2.1, iOS transitively)
Files Changed: 1 implementation, 0 test
Key Findings
- PR [inflight] Fix netstandard build break: ReferenceEqualityComparer in GradientBrush #36808 changes only
src/Controls/src/Core/GradientBrush.cs. - The PR fixes a build break introduced by using
System.Collections.Generic.ReferenceEqualityComparer.Instancein sharedControls.Core, which targetsnetstandard2.0andnetstandard2.1where that BCL comparer is unavailable/inaccessible. - The PR's current fix keeps the dictionary/ref-count design and swaps the BCL comparer for a private nested
IEqualityComparer<GradientStop>usingReferenceEqualsandRuntimeHelpers.GetHashCode. - Gate result was already completed separately and skipped because no tests were detected in this PR. No gate verification was re-run.
- No PR issue comments, inline review comments, or top-level reviews with prior error findings were found via the public GitHub API.
Code Review Summary
Verdict: NEEDS_DISCUSSION
Confidence: low
Errors: 0 | Warnings: 0 | Suggestions: 0
Key code review findings:
- Code review found no code findings.
- CI/required-check status was undetermined because
ghis unauthenticated in this environment; confidence is capped low by the code-review skill rules. - Blast radius: runs for all
GradientBrushinstances but only changes the private comparer used by the subscription ref-count dictionary; no startup path or mutable static state impact beyond a stateless comparer singleton. - Failure modes probed: equal-by-value distinct
GradientStopinstances remain independently tracked, duplicate same-stop references still ref-count, null stops are guarded before comparer use.
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #36808 | Replace unavailable BCL ReferenceEqualityComparer.Instance with a private nested reference comparer for GradientStop. |
src/Controls/src/Core/GradientBrush.cs |
Original PR |
🔬 Code Review — Deep Analysis
Code Review — PR #36808
Independent Assessment
What this changes: Replaces ReferenceEqualityComparer.Instance in GradientBrush with a private nested reference-identity comparer using ReferenceEquals and RuntimeHelpers.GetHashCode.
Inferred motivation: Avoid using a BCL API unavailable/inaccessible for Controls.Core netstandard targets while preserving reference-keyed subscription ref-count behavior.
Reconciliation with PR Narrative
Author claims: netstandard2.0/2.1 build breaks because ReferenceEqualityComparer is unavailable; fix is behaviorally equivalent.
Agreement/disagreement: Agrees. Controls.Core.csproj targets netstandard2.1;netstandard2.0, and the replacement preserves reference equality semantics.
Prior Review Reconciliation
No prior ❌ Error findings found.
Blast Radius Assessment
- Runs for all instances: Yes, for every
GradientBrushinstance, but only changes the dictionary comparer. - Startup impact: No.
- Static/shared state: Yes, one stateless comparer singleton; no mutable shared state.
CI Status
- Required-check result: tool-unavailable
- Classification: undetermined
- Action taken:
gh pr checks --requiredfailed becauseghis unauthenticated; capped confidence low.
Findings
No code findings.
Failure-Mode Probing
- Distinct equal-by-value
GradientStops: still tracked independently via reference equality. - Duplicate same stop instance: ref-counting still works.
- Null stops: existing guards prevent comparer use for null keys.
Verdict: NEEDS_DISCUSSION
Confidence: low
Summary: Code looks sound and localized, with no review findings. However CI status is undetermined because gh is unauthenticated, so per skill rules this cannot be LGTM.
🛠️ Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | try-fix-1 | Linear List<(GradientStop Stop, int Count)> with ReferenceEquals lookup. |
src/Controls/src/Core/GradientBrush.cs |
Avoids comparer/hash dependency but is O(n) and more mutation-prone than PR. | |
| 2 | try-fix-2 | Private GradientStopIdentity key struct with default Dictionary comparer. |
src/Controls/src/Core/GradientBrush.cs |
Preserves O(1) lookup but adds wrapper churn and more call-site complexity than PR. | |
| 3 | try-fix-3 | Snapshot-rebuild all subscriptions on every collection change. | src/Controls/src/Core/GradientBrush.cs |
Removes identity maps entirely but regresses duplicate-stop semantics and churns subscriptions. | |
| PR | PR #36808 | Private nested IEqualityComparer<GradientStop> using ReferenceEquals and RuntimeHelpers.GetHashCode. |
✅ Netstandard passed locally; Gate skipped because no tests detected | src/Controls/src/Core/GradientBrush.cs |
Smallest and most semantically equivalent fix. |
Cross-Pollination
| Model/Reviewer | Round | New Ideas? | Details |
|---|---|---|---|
| maui-expert-reviewer | 1 | Yes | Proposed linear reference-subscription table to remove comparer/hash semantics. |
| maui-expert-reviewer | 2 | Yes | Proposed identity-key wrapper to keep dictionary lookup without a custom comparer. |
| maui-expert-reviewer | 3 | Yes, but not recommended | Proposed snapshot-rebuild subscriptions as a final distinct approach; explicitly assessed as worse than PR. |
Test Summary
| Candidate | netstandard2.0 |
netstandard2.1 |
net10.0-ios26.0 |
|---|---|---|---|
| try-fix-1 | ✅ Passed | ✅ Passed | ❌ Failed in unrelated existing iOS analyzer/PublicAPI errors |
| try-fix-2 | ✅ Passed | ✅ Passed | ❌ Failed in unrelated existing iOS analyzer/PublicAPI errors |
| try-fix-3 | ✅ Passed | ✅ Passed | ❌ Failed in unrelated existing iOS analyzer/PublicAPI errors |
| PR baseline after restore | ✅ Passed | ✅ Passed | Not re-run after restore; same iOS errors were candidate-independent |
Failure Analysis / Lessons
- All alternatives fixed the original netstandard build break under targeted validation.
- The iOS platform build could not be used as a candidate discriminator because it consistently failed outside
GradientBrush.cs:src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/UIContainerCell.cs(17,22): error MEM0002- duplicate symbol entries in
src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt
- try-fix-1 is simpler conceptually but worse for performance and mutation surface.
- try-fix-2 is closest to viable but less readable than the PR because it spreads identity wrapping through each dictionary access.
- try-fix-3 exhausts a non-map strategy but introduces behavioral risks around duplicate same-instance stops and repeated invalidations.
Exhausted: Yes — remaining meaningful alternatives are worse than the PR's current private-comparer approach.
Selected Fix: PR #36808 — It is the smallest candidate, preserves the original dictionary/ref-count architecture, preserves exact reference-identity semantics, has no public API impact, and passes the targeted netstandard validation that covers the reported build break.
🏁 Report — Final Recommendation
Comparative Fix Report — PR #36808
Winner
Selected candidate: pr
The raw PR fix wins because it is the smallest semantically equivalent fix for the reported build break: it preserves the dictionary/ref-count design and replaces only the unavailable BCL reference comparer with a private cross-TFM comparer. The expert reviewer produced no actionable findings, so pr-plus-reviewer is identical to pr and does not improve on it.
Candidate ranking
| Rank | Candidate | Result | Rationale |
|---|---|---|---|
| 1 | pr |
✅ Targeted netstandard builds passed; gate skipped because no tests detected | Minimal change, preserves O(1) dictionary lookup, exact reference-identity semantics, and existing subscription lifecycle. |
| 2 | pr-plus-reviewer |
✅ Same as pr |
Expert reviewer returned no actionable findings, so this candidate is identical to pr; ranked below only because the raw PR is the actual submitted fix. |
| 3 | try-fix-2 |
✅ Netstandard passed; iOS blocked by unrelated existing errors | Viable identity-key wrapper, but adds a private key type and wrapper churn at every dictionary access with no benefit over the PR comparer. |
| 4 | try-fix-1 |
✅ Netstandard passed; iOS blocked by unrelated existing errors | Behaviorally plausible, but replaces O(1) dictionary lookup with O(n) list scans and more manual mutation logic. |
| 5 | try-fix-3 |
✅ Netstandard passed; iOS blocked by unrelated existing errors | Fixes the netstandard compile break, but is behaviorally riskier: rebuilds all subscriptions on every collection mutation and can duplicate subscriptions/invalidations for repeated same-instance stops. |
No candidate was ranked lower because of a candidate-specific regression-test failure. The iOS failures recorded for try-fix candidates were unrelated existing analyzer/PublicAPI errors outside GradientBrush.cs, and the gate result for the PR was skipped because no tests were detected.
Candidate details
pr
The PR replaces ReferenceEqualityComparer.Instance with a nested GradientStopReferenceComparer:
EqualsusesReferenceEquals.GetHashCodeusesRuntimeHelpers.GetHashCode.- The dictionary remains keyed by
GradientStop. - Existing ref-count semantics and subscription lifecycle stay unchanged.
This directly addresses the root cause: ReferenceEqualityComparer.Instance is unavailable/inaccessible for the shared netstandard2.0/netstandard2.1 Controls.Core target.
pr-plus-reviewer
The MAUI expert reviewer produced an empty inline findings array ([]). There was no feedback to apply, so this candidate is identical to pr.
try-fix-1
This candidate replaces the dictionary with List<(GradientStop Stop, int Count)> and performs linear ReferenceEquals lookup. It avoids comparer/hash dependencies and passed the netstandard builds, but it is less efficient and more mutation-heavy than the PR for no correctness gain.
try-fix-2
This candidate keeps dictionary lookup but changes the key to a private GradientStopIdentity struct. It is the strongest non-PR alternative because it preserves O(1)-style lookup and reference identity, but it spreads identity wrapping through subscribe/unsubscribe paths and is more complex than using a private comparer.
try-fix-3
This candidate removes the identity map and rebuilds subscriptions from the collection snapshot on each collection change. It is the weakest candidate because it changes incremental subscription behavior, can subscribe duplicate same-instance stops multiple times, and causes unnecessary churn.
Recommendation
Keep the PR fix as submitted. Consider adding targeted test coverage in a follow-up or in this PR if practical, because the gate detected no tests; however, lack of tests does not make any try-fix candidate preferable to the PR.
🧭 Next Steps — review latest findings
No alternative fix was selected for this run. Review the session findings and CI results before merging.
…GradientBrush (#36808) > [!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! ### Problem `GradientBrush` (added in #36746) keys its subscription ref-count dictionary with `System.Collections.Generic.ReferenceEqualityComparer.Instance`, which is **.NET 5+ only**. `Controls.Core` also targets **netstandard2.0/2.1**, so the shared build breaks: ``` src/Controls/src/Core/GradientBrush.cs(13,71): error CS0122: 'ReferenceEqualityComparer' is inaccessible due to its protection level [Controls.Core.csproj::TargetFramework=netstandard2.0] ``` This blocks every build of `inflight/current` (including Copilot PR reviews on inflight PRs, e.g. #36776, where the gate could not build the base). ### Fix Replace the BCL comparer with a small self-contained reference-identity comparer that works on **every** TFM — equality by object reference, hash from `RuntimeHelpers.GetHashCode` — preserving the leak fix's exact semantics. The other `ReferenceEqualityComparer` uses (`ShellRenderer.cs`, `MapHandler.Android.cs`) are in platform-specific files that only compile for .NET TFMs, so they are unaffected. ### Risk Minimal — behaviorally identical to `ReferenceEqualityComparer.Instance`; no public API change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
…GradientBrush (#36808) > [!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! ### Problem `GradientBrush` (added in #36746) keys its subscription ref-count dictionary with `System.Collections.Generic.ReferenceEqualityComparer.Instance`, which is **.NET 5+ only**. `Controls.Core` also targets **netstandard2.0/2.1**, so the shared build breaks: ``` src/Controls/src/Core/GradientBrush.cs(13,71): error CS0122: 'ReferenceEqualityComparer' is inaccessible due to its protection level [Controls.Core.csproj::TargetFramework=netstandard2.0] ``` This blocks every build of `inflight/current` (including Copilot PR reviews on inflight PRs, e.g. #36776, where the gate could not build the base). ### Fix Replace the BCL comparer with a small self-contained reference-identity comparer that works on **every** TFM — equality by object reference, hash from `RuntimeHelpers.GetHashCode` — preserving the leak fix's exact semantics. The other `ReferenceEqualityComparer` uses (`ShellRenderer.cs`, `MapHandler.Android.cs`) are in platform-specific files that only compile for .NET TFMs, so they are unaffected. ### Risk Minimal — behaviorally identical to `ReferenceEqualityComparer.Instance`; no public API change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
…GradientBrush (#36808) > [!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! ### Problem `GradientBrush` (added in #36746) keys its subscription ref-count dictionary with `System.Collections.Generic.ReferenceEqualityComparer.Instance`, which is **.NET 5+ only**. `Controls.Core` also targets **netstandard2.0/2.1**, so the shared build breaks: ``` src/Controls/src/Core/GradientBrush.cs(13,71): error CS0122: 'ReferenceEqualityComparer' is inaccessible due to its protection level [Controls.Core.csproj::TargetFramework=netstandard2.0] ``` This blocks every build of `inflight/current` (including Copilot PR reviews on inflight PRs, e.g. #36776, where the gate could not build the base). ### Fix Replace the BCL comparer with a small self-contained reference-identity comparer that works on **every** TFM — equality by object reference, hash from `RuntimeHelpers.GetHashCode` — preserving the leak fix's exact semantics. The other `ReferenceEqualityComparer` uses (`ShellRenderer.cs`, `MapHandler.Android.cs`) are in platform-specific files that only compile for .NET TFMs, so they are unaffected. ### Risk Minimal — behaviorally identical to `ReferenceEqualityComparer.Instance`; no public API change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
…GradientBrush (#36808) > [!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! ### Problem `GradientBrush` (added in #36746) keys its subscription ref-count dictionary with `System.Collections.Generic.ReferenceEqualityComparer.Instance`, which is **.NET 5+ only**. `Controls.Core` also targets **netstandard2.0/2.1**, so the shared build breaks: ``` src/Controls/src/Core/GradientBrush.cs(13,71): error CS0122: 'ReferenceEqualityComparer' is inaccessible due to its protection level [Controls.Core.csproj::TargetFramework=netstandard2.0] ``` This blocks every build of `inflight/current` (including Copilot PR reviews on inflight PRs, e.g. #36776, where the gate could not build the base). ### Fix Replace the BCL comparer with a small self-contained reference-identity comparer that works on **every** TFM — equality by object reference, hash from `RuntimeHelpers.GetHashCode` — preserving the leak fix's exact semantics. The other `ReferenceEqualityComparer` uses (`ShellRenderer.cs`, `MapHandler.Android.cs`) are in platform-specific files that only compile for .NET TFMs, so they are unaffected. ### Risk Minimal — behaviorally identical to `ReferenceEqualityComparer.Instance`; no public API change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
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!
Problem
GradientBrush(added in #36746) keys its subscription ref-count dictionary withSystem.Collections.Generic.ReferenceEqualityComparer.Instance, which is .NET 5+ only.Controls.Corealso targets netstandard2.0/2.1, so the shared build breaks:This blocks every build of
inflight/current(including Copilot PR reviews on inflight PRs, e.g. #36776, where the gate could not build the base).Fix
Replace the BCL comparer with a small self-contained reference-identity comparer that works on every TFM — equality by object reference, hash from
RuntimeHelpers.GetHashCode— preserving the leak fix's exact semantics.The other
ReferenceEqualityCompareruses (ShellRenderer.cs,MapHandler.Android.cs) are in platform-specific files that only compile for .NET TFMs, so they are unaffected.Risk
Minimal — behaviorally identical to
ReferenceEqualityComparer.Instance; no public API change.