System.Drawing.PointConverter cannot convert values with leading white-space
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Description
We have WinForms projects on .NET Framework that we are migrating to .NET 10+.
We've found that InitializeComponent throws on .NET 10:
```
System.ArgumentException : is not a valid value for Int32. (Parameter 'value')
----> System.IndexOutOfRangeException : Index was outside the bounds of the array.
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.Drawing.PointConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.Resources.Extensions.DeserializingResourceReader.DeserializeObject(Int32 typeIndex)
at System.Resources.Extensions.DeserializingResourceReader._LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)
at System.Resources.Extensions.DeserializingResourceReader.LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)
[...]
```
This was traced back to having Points in the .resx files with leading white-space, e.g. ` 2, 200`. This works find on .NET Framework.
### Reproduction Steps
```
foreach (var s in new[] { "1,200", " 2, 200", " 3 , 200" })
{
Console.WriteLine(new System.Drawing.PointConverter().ConvertFrom(s));
}
```
[PointConverterTest.zip](https://github.com/user-attachments/files/30012483/PointConverterTest.zip)
### Expected behavior
Values with leading white-space can be converted.
All target frameworks (4.8, 10, 11) should print
```
{X=1,Y=200}
{X=2,Y=200}
{X=3,Y=200}
```
### Actual behavior
Exception on 10 and 11:
```
System.ArgumentException
HResult=0x80070057
Message= is not a valid value for Int32. (Parameter 'value')
Source=System.ComponentModel.TypeConverter
StackTrace:
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.Drawing.PointConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at Program.$(String[] args) in C:\slb\PointConverterTest\PointConverterTest\Program.cs:line 3
This exception was originally thrown at this call stack:
System.ComponentModel.BaseNumberConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext, System.Globalization.CultureInfo, object)
Inner Exception 1:
IndexOutOfRangeException: Index was outside the bounds of the array.
```
### Regression?
Yes, works on 4.8
### Known Workarounds
NA
### Configuration
10.x, 11.x (various versions), x64, Windows
### Other information
_No response_
Contributor guide
Research direction
Start with System.Drawing.PointConverter.ConvertFrom and the BaseNumberConverter path shown in the stack trace, then run the supplied reproduction with the three point strings on the target frameworks. Compare the results with .NET Framework 4.8. Done means leading whitespace converts successfully and all target frameworks print the expected Point values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100