Fix data binding fallback update for uncreated controls#14677
Open
abineshPalanisamy wants to merge 5 commits into
Open
Fix data binding fallback update for uncreated controls#14677abineshPalanisamy wants to merge 5 commits into
abineshPalanisamy wants to merge 5 commits into
Conversation
Fix has been added for the issue.
Added unit test cases for the Fix_Issue_13470
Addressed the review correction for Fix_Issue_13470
…into Fix_Issue_13470
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a WinForms data binding crash when BindingManagerBase.PushData() pushes updates to bindings whose target controls haven’t created their handles yet (e.g., controls hosted on an inactive TabPage). The change prevents the inactive-binding fallback path from pushing a null value into an uncreated control, which could otherwise coerce to an invalid default (like 0) and trigger ArgumentOutOfRangeException for value-type properties such as NumericUpDown.Value.
Changes:
- Guard
Binding.PushData(bool force)so the inactive-binding fallback (SetPropValue(null)) only runs when the target component is already created. - Add regression tests covering a bound
NumericUpDownon an inactive tab page (no throw during shared manager updates; correct value after tab activation). - Add a test ensuring
Binding.ReadValue()does not throw for an uncreatedNumericUpDownwithMinimumset.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/System.Windows.Forms/System/Windows/Forms/DataBinding/Binding.cs | Avoids calling SetPropValue(null) for inactive bindings when the target control isn’t created, preventing invalid fallback writes. |
| src/test/unit/System.Windows.Forms/System/Windows/Forms/BindingTests.cs | Adds regression coverage for inactive-tab NumericUpDown binding updates and uncreated-control ReadValue() behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Addressed the review correction for Fix_Issue_13470
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13470
Proposed changes
Binding.PushData(bool force)to avoid callingSetPropValue(null)when the binding is inactive and the target component has not yet been created.BindingTestsfor a boundNumericUpDownhosted on an inactiveTabPage, where the target control is not yet created and a shared binding manager pushes updates to all bindings.Root cause
BindingManagerBase.BindingManagerBase.PushData()attempts to push data to all associated bindings.TabPage, the target control may not be created yet.IsBinding == false), butBinding.PushData(bool force)still executes the fallback path and callsSetPropValue(null).0.NumericUpDown.Minimumis set to8, so assigning0toNumericUpDown.ValuecausesArgumentOutOfRangeException.Customer Impact
NumericUpDownis hosted inside an inactive or invisible container, such as an unselectedTabPage.Regression?
Risk
Binding.PushData(bool force).Screenshots
Before
Databinding_Before_fix.mp4
After
Databinding_After_fix.mp4
Test methodology
Reproduced the issue scenario described in the GitHub issue:
TabControlcontains twoTabPageinstances.NumericUpDown.NumericUpDownis placed on an inactive tab page and hasMinimumset to8.NumericUpDowntriggers a binding update through the sharedBindingManagerBase.ArgumentOutOfRangeExceptionbecause the inactive binding path pushes an invalid fallback value to the uncreated target control.Verified that the updated
Binding.PushData(bool force)behavior avoids callingSetPropValue(null)when the target component has not yet been created.Added unit test coverage in
BindingTeststo validate that:NumericUpDownis on an inactive tab;Verified that the existing inactive-binding fallback behavior is preserved when the target component is already created.
Accessibility testing
Test environment(s)
Microsoft Reviewers: Open in CodeFlow