Regression in double properties and NaN
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
Throw helpers introduced in https://github.com/dotnet/wpf/pull/8408 caused a behavioral regression thus some double properties no longer accept NaN as a value.
The original condition in net framework and up to net8 was `value < 0`, the new condition is `double.IsNegative(value)`. The latter now causes an `ArgumentOutOfRangeException`. See https://github.com/dotnet/runtime/issues/92834#issuecomment-1741525749 on why these are not the same.
### Reproduction Steps
```
// Get an existing visual
TextBox tb = ...
// Prepare some other text using the same parameters
FormattedText ft = new(...);
ft.LineHeight = tb.LineHeight;
```
### Expected behavior
Property value is accepted
### Actual behavior
ArgumentOutOfRangeException is thrown
### Regression?
Yes. Works in .NET Framework and up to .NET 8
### Known Workarounds
In the example above it's simple to fix as NaN is eventually treated as 0 (converted to int.MinValue [here](https://github.com/dotnet/wpf/blob/b63ac07fbc7a58fde79f14a842b7816ebfb7e96d/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs#L700) then ignored [here](https://github.com/dotnet/wpf/blob/b63ac07fbc7a58fde79f14a842b7816ebfb7e96d/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextMetrics.cs#L185)) though this does not seem intentional.
Other properties may be more difficult to work around
### Impact
_No response_
### Configuration
_No response_
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.