Skip to content

Conversation

@StephaneDelcroix
Copy link
Contributor

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

Changes

  • Changed SolidColorBrush.Equals to use Equals(Color, dest.Color) instead of Color == dest.Color
  • Added unit test SolidColorBrushEqualsComparesColorValues to verify the fix

Root Cause

Color is a class, and OnPlatform<Color> creates a new Color instance each time it is evaluated. When SolidColorBrush.Equals compared colors using ==, it was doing reference comparison instead of value comparison. This caused VisualElement.OnParentResourcesChanged to detect a "change" every time (even when the color values were identical), leading to an infinite loop.

Fix

Use Equals() which delegates to Color.Equals(), which compares colors by their RGBA values (via ToInt()).

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().
Copilot AI review requested due to automatic review settings December 2, 2025 11:51
@StephaneDelcroix StephaneDelcroix added this to the .NET 10.0 SR2 milestone Dec 2, 2025
@StephaneDelcroix StephaneDelcroix added the p/0 Current heighest priority issues that we are targeting for a release. label Dec 2, 2025
Copy link
Contributor

Copilot AI left a comment

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 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.Equals to 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 jfversluis merged commit db3517c into main Dec 2, 2025
67 of 68 checks passed
@jfversluis jfversluis deleted the fix/27281-solidcolorbrush-equals branch December 2, 2025 14:08
@PureWeen PureWeen added the area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing label 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 [@&#8203;PureWeen](https://github.com/PureWeen) in dotnet/maui#32340

-   \[AI] The Issue-Resolver agent by [@&#8203;kubaflo](https://github.com/kubaflo) in dotnet/maui#32804

-   \[AI] Fixed links for agents by [@&#8203;kubaflo](https://github.com/kubaflo) in dotnet/maui#32818

-   Add checkpoint/resume system for PR review agent by [@&#8203;kubaflo](https://github.com/kubaflo) in dotnet/maui#32774

-   Improved pr-reviewer AI agent and modified the usage instructions in README by [@&#8203;kubaflo](https://github.com/kubaflo) in dotnet/maui#32718

-   Agents scripts by [@&#8203;PureWeen](https://github.com/PureWeen) in dotnet/maui#32819

-   Simplify agent instructions and consolidate sandbox testing workflow by [@&#8203;Copilot](https://github.com/Copilot) in dotnet/maui#32950

##### Brushes

-   Fix SolidColorBrush.Equals to compare Color values instead of references by [@&#8203;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 [@&#8203;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 [@&#8203;PureWeen](https://github.com/PureWeen) in dotnet/maui#32502

-   Improve AI agent documentation and testing instructions by [@&#8203;Copilot](https://github.com/Copilot) in https://github.com/dotnet/maui/p...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing p/0 Current heighest priority issues that we are targeting for a release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Application freezes when Background property is set to a DynamicResource of type OnPlatform Color

4 participants