[release/v7.4] Fix Out-GridView by replacing use of obsolete BinaryFormatter with custom implementation.#26866
Conversation
…h custom implementation (PowerShell#25497)
There was a problem hiding this comment.
Pull request overview
This PR backports a fix for Out-GridView filtering from the master branch to release/v7.4. The fix addresses a critical regression where Out-GridView's text search functionality broke after .NET 9 removed BinaryFormatter from the runtime. The solution replaces the obsolete BinaryFormatter-based deep cloning with a custom implementation using a new IDeepCloneable interface and copy constructors.
Changes:
- Introduced
IDeepCloneableinterface for custom deep cloning - Implemented copy constructors across all FilterRule and ValidatingValue classes
- Removed BinaryFormatter dependency from FilterRuleExtensions
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| IDeepCloneable.cs | New interface defining the DeepClone() method contract |
| DataErrorInfoValidationRule.cs | Added IDeepCloneable interface and abstract DeepClone() method |
| ValidatingValueBase.cs | Added copy constructor to support deep cloning of validation rules |
| ValidatingValue.cs | Implemented copy constructor and DeepClone() method with support for IDeepCloneable values |
| ValidatingSelectorValue.cs | Implemented copy constructor with type-safe deep cloning of available values |
| FilterRule.cs | Added copy constructor and DeepClone() implementation using Activator.CreateInstance |
| TextStartsWithFilterRule.cs | Added copy constructor following the established pattern |
| TextFilterRule.cs | Added copy constructor to propagate IgnoreCase and CultureInvariant properties |
| TextEqualsFilterRule.cs | Added copy constructor |
| TextEndsWithFilterRule.cs | Added copy constructor |
| TextDoesNotEqualFilterRule.cs | Added copy constructor |
| TextDoesNotContainFilterRule.cs | Added copy constructor |
| TextContainsFilterRule.cs | Added copy constructor |
| SingleValueComparableValueFilterRule.cs | Added copy constructor with deep cloning of Value property |
| SelectorFilterRule.cs | Added copy constructor with proper event handler attachment |
| PropertyValueSelectorFilterRule.cs | Added copy constructor to copy PropertyName and initialize DisplayNameConverter |
| PropertiesTextContainsFilterRule.cs | Added copy constructor to copy PropertyNames list |
| IsNotEmptyValidationRule.cs | Implemented DeepClone() method for stateless validation rule |
| IsNotEmptyFilterRule.cs | Added copy constructor |
| IsLessThanFilterRule.cs | Added copy constructor |
| IsGreaterThanFilterRule.cs | Added copy constructor |
| IsEmptyFilterRule.cs | Added copy constructor |
| IsBetweenFilterRule.cs | Added copy constructor with deep cloning of StartValue and EndValue |
| FilterRuleExtensions.cs | Replaced BinaryFormatter implementation with simple call to DeepClone() |
| EqualsFilterRule.cs | Added copy constructor |
| DoesNotEqualFilterRule.cs | Added copy constructor |
| ComparableValueFilterRule.cs | Added copy constructor to propagate DefaultNullValueEvaluation |
| public override object DeepClone() | ||
| { | ||
| // Instance is stateless. | ||
| // return this; |
There was a problem hiding this comment.
Consider removing the commented-out code. The comment "Instance is stateless" explains the decision, but the commented code (return this;) should be removed to keep the codebase clean.
| // return this; |
Backport of #25497 to release/v7.4
Triggered by @TravisEz13 on behalf of @mawosoft
Original CL Label: CL-General
/cc @PowerShell/powershell-maintainers
Impact
REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.
Tooling Impact
Customer Impact
Fixes #24749 / #14054 where Out-GridView filtering is broken because BinaryFormatter was removed. Expected: filtering works. Actual: filtering fails.
Regression
REQUIRED: Check exactly one box.
Regression introduced after switching to .NET 9 in PowerShell 7.5.
Testing
Not run locally; issue is interactive per original PR notes.
Risk
REQUIRED: Check exactly one box.
User-facing UI behavior change scoped to Out-GridView filter rules; no broad engine impact.