Fix exception on parse failure for unsigned types in BindConverter#67091
Open
irfanajaffer wants to merge 7 commits into
Open
Fix exception on parse failure for unsigned types in BindConverter#67091irfanajaffer wants to merge 7 commits into
irfanajaffer wants to merge 7 commits into
Conversation
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.
Description:
When attempting to convert negative values to unsigned integer types (uint, ushort, ulong, byte), the TypeConverter throws an ArgumentException. While the BindConverter correctly catches this exception and returns false (as expected behavior), the test suite lacked comprehensive coverage to verify this behavior across all unsigned types and edge cases
Root Cause
The BindConverter uses TypeDescriptor/TypeConverter for unsigned integer types (uint, ushort, ulong, byte, sbyte) since they don't have explicit handling in the ParserDelegateCache. When invalid values (like negative numbers for unsigned types) are passed, the TypeConverter throws ArgumentException, which is properly caught and handled by returning false.
Testing
Added comprehensive unit tests in BindConverterTest.cs to validate handling of unsigned integer types across all key scenarios. The tests ensure:
✅ Valid conversions succeed as expected
✅ Negative inputs return false without throwing (verifies ArgumentException handling)
✅ Out-of-range values return false (verifies OverflowException handling)
✅ Null and empty string inputs are handled gracefully
✅ Nullable unsigned type conversions behave correctly
✅ Boundary values (MinValue/MaxValue) are processed accurately
Fixes #42435