wpf icon indicating copy to clipboard operation
wpf copied to clipboard

NET 7.0 Windows.Media.Color fails to convert to string using ToString() when created by the FromScRgb method

Open charint0 opened this issue 3 years ago • 4 comments

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:

  1. Create an instance of a variable of type System.Windows.Media.Color with the method FromScRgb (float a, float r, float g, float b);
  2. call ToString()
  3. 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, ReadOnlySpan1 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

charint0 avatar May 18 '23 15:05 charint0

cc @gomathip02 @vatsan-madhavan

eiriktsarpalis avatar May 22 '23 13:05 eiriktsarpalis

@dotnet/wpf-developers is likely a better contact; I haven't been looking at wpf for a while now.

vatsan-madhavan avatar May 22 '23 14:05 vatsan-madhavan

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

RxDave avatar Jun 13 '23 05:06 RxDave

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

miloush avatar Jun 13 '23 23:06 miloush