NET 7.0 Windows.Media.Color fails to convert to string using ToString() when created by the FromScRgb method
Description
I have this problem after upgrading to NET 7.0.201 from NET 6.
Minimal code steps to reproduce :
var color = System.Windows.Media.Color.FromScRgb(1, 1, 1, 1);
color.ToString(); // throws System.FormatException
Description:
- Create an instance of a variable of type System.Windows.Media.Color with the method FromScRgb (float a, float r, float g, float b);
- call ToString()
- An Exception of type 'System.FormatException' is thrown:
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233033
HelpLink: null
InnerException: null
Message: "Input string was not in a correct format."
Source: "System.Private.CoreLib"
StackTrace: " at System.Text.ValueStringBuilder.ThrowFormatInvalidString()\r\n at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ReadOnlySpan
1 args)\r\n at System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan1 args)\r\n at System.String.Format(IFormatProvider provider, String format, Object[] args)\r\n at System.Windows.Media.Color.ConvertToString(String format, IFormatProvider provider)" TargetSite: {Void ThrowFormatInvalidString()}
Configuration
NET 7.0.201 OS: Windows 10 Enterprise version 22H2 OS BUILD 19045.2728 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz 3.41 GHz x64
Regression?
This bug is not present in NET 6
cc @gomathip02 @vatsan-madhavan
@dotnet/wpf-developers is likely a better contact; I haven't been looking at wpf for a while now.
I've just run into the same error. Here's a simple workaround, for now:
System.Windows.Media.Color color = Color.FromScRgb(1, 1, 1, 1);
var s = Convert.ToString(color); // No exception is thrown; result is #FFFFFFFF
https://github.com/dotnet/wpf/pull/6275 broke this @stephentoub @lindexi, people need to be testing the code they change, CI is not good enough