-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix issue 14187: PropertyGrid.SelectedObjects shows empty grid with typed arrays when PropertySort is NoSort (.NET 9/10 regression) #14190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a .NET 9/10 regression where PropertyGrid.SelectedObjects displays an empty grid when using typed arrays with PropertySort set to NoSort. The issue stems from Span enforcing exact type matching, which causes ArrayTypeMismatchException when working with typed arrays like ItemTypeDescriptor[].
Key Changes:
- Added empty array boundary check to prevent null reference issues
- Introduced intermediate object?[] arrays to work around Span covariance limitations
- Restructured single-object and multi-object handling logic
.../Forms/Controls/PropertyGrid/PropertyGridInternal/MultiSelectRootGridEntry.PropertyMerger.cs
Outdated
Show resolved
Hide resolved
.../Forms/Controls/PropertyGrid/PropertyGridInternal/MultiSelectRootGridEntry.PropertyMerger.cs
Show resolved
Hide resolved
.../Forms/Controls/PropertyGrid/PropertyGridInternal/MultiSelectRootGridEntry.PropertyMerger.cs
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #14190 +/- ##
===================================================
+ Coverage 77.15242% 77.16063% +0.00820%
===================================================
Files 3279 3279
Lines 645333 645403 +70
Branches 47720 47726 +6
===================================================
+ Hits 497890 497997 +107
+ Misses 143757 143717 -40
- Partials 3686 3689 +3
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
KlausLoeffelmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SimonZhao888, can you please address the Copilot comments, before I review?
Also, a question:
Could you comment on what the introduction of nullablility regressed and how?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
.../Forms/Controls/PropertyGrid/PropertyGridInternal/MultiSelectRootGridEntry.PropertyMerger.cs
Outdated
Show resolved
Hide resolved
.../Forms/Controls/PropertyGrid/PropertyGridInternal/MultiSelectRootGridEntry.PropertyMerger.cs
Show resolved
Hide resolved
.../Forms/Controls/PropertyGrid/PropertyGridInternal/MultiSelectRootGridEntry.PropertyMerger.cs
Show resolved
Hide resolved
OK, got it! |
|
Nullable Introduction Regression (What regressed and how) After introducing nullable annotations, the type signature of SelectedObjects changed from object[] to object?[]. This change affected generic inference and internal handling in the following ways: Previously, the code assumed SelectedObjects was always a “real object[]” and that writes would not trigger type mismatch issues. In short, nullable annotations widened the API’s accepted type range, making it easier for covariant arrays to enter the code path and exposing a latent risk of unsafe writes. |
ricardobossan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All LGTM!
Fixes #14187
Root Cause
PropertyGrid.SelectedObjects accepts a covariant array (for example, CustomTypeDescriptor[]), and during subsequent property-merging logic, the internal code treats this array as object?[] and attempts to write elements into it. Because the CLR enforces runtime type checks on covariant arrays, writing an element whose type does not match the underlying array’s actual element type triggers an ArrayTypeMismatchException.
Span’s invariance prevents converting a covariant array directly into Span<object?>, but this is not the fundamental cause of the exception—the root issue is unsafe writes to a covariant array. The GetMergedProperties method returning null is a secondary symptom of the error chain, not the root cause.
Proposed changes
Customer Impact
Regression?
Risk
Screenshots
Before
Before.mp4
After
After.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow