Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Controls/src/Core/SolidColorBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override bool Equals(object obj)
if (!(obj is SolidColorBrush dest))
return false;

return Color == dest.Color;
return Equals(Color, dest.Color);
}

/// <include file="../../docs/Microsoft.Maui.Controls/SolidColorBrush.xml" path="//Member[@MemberName='GetHashCode']/Docs/*" />
Expand Down
25 changes: 25 additions & 0 deletions src/Controls/tests/Core.UnitTests/SolidColorBrushTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,30 @@ public void TestDefaultBrushes()
Assert.NotNull(white.Color);
Assert.Equal(white.Color, Colors.White);
}

[Fact]
// https://github.com/dotnet/maui/issues/27281
public void SolidColorBrushEqualsComparesColorValues()
{
// Create two Color instances with identical RGBA values but different object references
// This simulates what happens with OnPlatform<Color> which creates new Color instances
var color1 = new Color(1.0f, 0.0f, 0.0f, 1.0f);
var color2 = new Color(1.0f, 0.0f, 0.0f, 1.0f);

// Verify these are different instances
Assert.False(ReferenceEquals(color1, color2));

// Verify the Color.Equals method returns true for same values
Assert.True(color1.Equals(color2));

// Create SolidColorBrush instances with these colors
var brush1 = new SolidColorBrush(color1);
var brush2 = new SolidColorBrush(color2);

// This is the bug from issue #27281: SolidColorBrush.Equals uses '==' for Color comparison
// which compares references instead of values, causing infinite loops with DynamicResource
// and OnPlatform<Color> because OnPlatform creates new Color instances each time
Assert.True(brush1.Equals(brush2));
}
}
}
Loading