Fix SolidColorBrush.Equals to compare Color values instead of references#32956
Merged
jfversluis merged 1 commit intomainfrom Dec 2, 2025
Merged
Fix SolidColorBrush.Equals to compare Color values instead of references#32956jfversluis merged 1 commit intomainfrom
jfversluis merged 1 commit intomainfrom
Conversation
Fixes #27281 The issue was that SolidColorBrush.Equals used '==' to compare Color objects, which compares references instead of values. This caused infinite loops when using DynamicResource with OnPlatform<Color> because OnPlatform creates new Color instances each time, and the equality check would always return false even for identical color values. Changed to use Equals() which properly compares Color values via Color.Equals().
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an infinite loop issue (#27281) in SolidColorBrush.Equals by changing from reference comparison (==) to value comparison (Equals()) for Color objects. The problem occurred when DynamicResource was used with OnPlatform<Color>, which creates new Color instances each time, causing the reference comparison to always fail even for identical color values.
Key Changes
- Fixed
SolidColorBrush.Equalsto compare Color values instead of references - Added comprehensive unit test to prevent regression
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Controls/src/Core/SolidColorBrush.cs | Changed Color comparison from == to Equals(Color, dest.Color) for proper value comparison |
| src/Controls/tests/Core.UnitTests/SolidColorBrushTests.cs | Added test SolidColorBrushEqualsComparesColorValues to verify Colors with identical RGBA values are considered equal even with different object references |
jfversluis
approved these changes
Dec 2, 2025
This was referenced Dec 16, 2025
Merged
This was referenced Dec 17, 2025
evgenygunko
pushed a commit
to evgenygunko/CopyWordsDA
that referenced
this pull request
Dec 18, 2025
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [Microsoft.Maui.Controls](https://github.com/dotnet/maui) | nuget | patch | `10.0.11` -> `10.0.20` | --- ### Release Notes <details> <summary>dotnet/maui (Microsoft.Maui.Controls)</summary> ### [`v10.0.20`](https://github.com/dotnet/maui/releases/tag/10.0.20): SR2 [Compare Source](dotnet/maui@10.0.11...10.0.20) ##### What's Changed **Note:** This is a service release (SR2) tracking ongoing release/10.0.1xx-sr2 branch development. The version number 10.0.20 represents the second service release for .NET MAUI 10. .NET MAUI 10.0.20 development introduces significant improvements across all platforms with focus on quality, performance, and developer experience. Current development includes enhancements to XAML Source Generator, iOS/macOS fixes, AppThemeBinding improvements, and improved developer tooling. ##### AI - PR Reviewer Agent by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#32340 - \[AI] The Issue-Resolver agent by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32804 - \[AI] Fixed links for agents by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32818 - Add checkpoint/resume system for PR review agent by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32774 - Improved pr-reviewer AI agent and modified the usage instructions in README by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32718 - Agents scripts by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#32819 - Simplify agent instructions and consolidate sandbox testing workflow by [@​Copilot](https://github.com/Copilot) in dotnet/maui#32950 ##### Brushes - Fix SolidColorBrush.Equals to compare Color values instead of references by [@​StephaneDelcroix](https://github.com/StephaneDelcroix) in dotnet/maui#32956 <details> <summary>🔧 Fixes</summary> - [Using DynamicResource with OnPlatform<Color> causes infinite loop](dotnet/maui#27281) </details> ##### Data Binding - Fix CS8603 error for nullable reference types in SourceGen binding paths by [@​Copilot](https://github.com/Copilot) in dotnet/maui#32480 <details> <summary>🔧 Fixes</summary> - [error CS8603: Possible null reference return in generated code using SourceGen](dotnet/maui#32478) </details> ##### Docs - Add README-AI.md file by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#32502 - Improve AI agent documentation and testing instructions by [@​Copilot](https://github.com/Copilot) in https://github.com/dotnet/maui/p...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Fixes #27281
The issue was that
SolidColorBrush.Equalsused==to compareColorobjects, which compares references instead of values. This caused infinite loops when usingDynamicResourcewithOnPlatform<Color>becauseOnPlatformcreates newColorinstances each time, and the equality check would always return false even for identical color values.Changes
SolidColorBrush.Equalsto useEquals(Color, dest.Color)instead ofColor == dest.ColorSolidColorBrushEqualsComparesColorValuesto verify the fixRoot Cause
Coloris a class, andOnPlatform<Color>creates a newColorinstance each time it is evaluated. WhenSolidColorBrush.Equalscompared colors using==, it was doing reference comparison instead of value comparison. This causedVisualElement.OnParentResourcesChangedto detect a "change" every time (even when the color values were identical), leading to an infinite loop.Fix
Use
Equals()which delegates toColor.Equals(), which compares colors by their RGBA values (viaToInt()).