Repository navigation
System.Data.OleDb: throw ArgumentOutOfRangeException from OleDbParameterCollection.RemoveAt(int) - #137041
Open
alaricd wants to merge 2 commits into
Open
System.Data.OleDb: throw ArgumentOutOfRangeException from OleDbParameterCollection.RemoveAt(int)#137041alaricd wants to merge 2 commits into
alaricd wants to merge 2 commits into
Conversation
…index IList.RemoveAt documents ArgumentOutOfRangeException for an index that is not valid. OleDbParameterCollection.RemoveAt(int) throws IndexOutOfRangeException, so the invalid-index tests fail until the next commit. Valid-index behavior, the Int32 overload through IList and DbParameterCollection, and the behavior that must not change (RemoveAt(string), the indexer) are pinned as well. The tests need no OLE DB provider, and the new-behavior ones are skipped on .NET Framework, which keeps the old exception type.
…eAt(int)
IList.RemoveAt documents ArgumentOutOfRangeException when the index is not valid.
OleDbParameterCollection.RemoveAt(int) threw IndexOutOfRangeException through
RangeCheck. It now throws ArgumentOutOfRangeException (ParamName "index", ActualValue
the index) with the existing "Invalid index {0} for this OleDbParameterCollection with
Count={2}." message. The indexer and the name-based members are unchanged.
Fixes dotnet#137039
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-collections |
alaricd
marked this pull request as ready for review
November 5, 2026 20:03
1 of 3 tasks
This branch has not been deployed
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 #137039
Problem
OleDbParameterCollectionis anIList(throughDbParameterCollection). The documentation ofIList.RemoveAtlistsArgumentOutOfRangeExceptionfor an index that is not valid ("indexis not a valid index in the IList").OleDbParameterCollection.RemoveAt(int)instead threwIndexOutOfRangeException(throughRangeCheck), which is not a subclass of it, so acatch (ArgumentOutOfRangeException)written against the documented contract did not catch it.Insert(-1, ...)on the same collection already throwsArgumentOutOfRangeException, so the collection was inconsistent with itself.Change
RemoveAt(int)now throwsArgumentOutOfRangeExceptionfor an index outside0..Count-1, withParamName == "index",ActualValueset to the index, and the same message as before ("Invalid index {0} for this OleDbParameterCollection with Count={2}."). Nothing else changes: the indexer,RemoveAt(string)and the other members keep usingRangeCheck/IndexOutOfRangeException, and tests pin that.The scope is deliberately one method. The indexer getter has the same shape, but its documentation is a separate question and I would rather not widen a compatibility-sensitive change.
Compatibility
This is a behavior change: code that catches
IndexOutOfRangeExceptionaroundOleDbParameterCollection.RemoveAt(int)will no longer catch it. I believe the old behavior is inherited from .NET Framework, andSqlParameterCollectionhas the same pattern, so I raised it as an issue first (#137039) and am sending this as a draft until maintainers say whether they want it. If the answer is "by design", I will close this and propose a documentation note instead. The new tests are skipped on .NET Framework, which keeps the old exception type.Tests
OleDbParameterCollectionTestsis new and needs no OLE DB provider (a command and its parameters can be created without a connection), so it runs wherever the OleDb tests are built:int.MinValue/int.MaxValue; two items with 2/3/-1/int.MaxValue) throwArgumentOutOfRangeExceptionwith the rightParamNameandActualValueand leave the collection unchanged;IListandDbParameterCollection;RemoveAt(string)for a missing name and the indexer still throwIndexOutOfRangeException.The first commit adds the tests and fails against the old code; the second makes them pass.
I have not run these tests locally, and CI has not run them yet. Building dotnet/runtime's library tests needs a CoreCLR build, which my environment cannot do (no C++ toolchain). The PR is now ready for review, but the full build and test pipelines still need a maintainer to start them on this fork-based PR. I checked the code by reading it against the surrounding sources only; please run the pipelines, and until a green run exists, please treat the tests as unverified and tell me if anything fails to compile.
How this was found
Found by pengdows.AdoNetApiTest.conformance, an xUnit conformance suite for ADO.NET providers that checks the documented
System.Data.Commoncontract (forked from mysql-net/AdoNetApiTest). Its testsParameterCollection_RemoveAt_zero_throws_when_emptyandParameterCollection_RemoveAt_negative_one_throwsfailed forSystem.Data.OleDb. The reproduction in #137039 needs no database.