SqlBatch.ValidateExecuteCommandBehavior XML comment says NotSupportedException but code throws ArgumentOutOfRangeException
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 90/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- csharp
- Domain
- databases, documentation
Research direction
Start at the /// comment on ValidateExecuteCommandBehavior in src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBatch.cs (around line 382) and check the NotSupportedCommandBehavior helper in AdapterUtil.cs, which returns ArgumentOutOfRangeException. Run SqlBatchTest.cs in tests/UnitTests (lines 22 and 32) to confirm the expected type. Done when the cref names ArgumentOutOfRangeException and the unit tests still pass; the doc/snippets SqlBatch.xml wording is optional.
Written by the indexing model from the issue text.
Description
Description
The /// comment on SqlBatch.ValidateExecuteCommandBehavior documents the wrong exception type.
/// <exception cref="NotSupportedException">Thrown when unsupported behavior flags are detected.</exception>
internal static void ValidateExecuteCommandBehavior(string method, CommandBehavior behavior)
The method throws through ADP.NotSupportedCommandBehavior (line 388), which returns an ArgumentOutOfRangeException (AdapterUtil.cs line 1333):
internal static ArgumentOutOfRangeException NotSupportedCommandBehavior(CommandBehavior value, string method)
=> NotSupportedEnumerationValue(typeof(CommandBehavior), value.ToString(), method);
The unit tests assert ArgumentOutOfRangeException for both an invalid value and a valid but unsupported value such as CommandBehavior.KeyInfo (SqlBatchTest.cs lines 22 and 32).
The method is called from ExecuteReader and ExecuteReaderAsync, so callers passing KeyInfo, SchemaOnly, SingleResult, or SingleRow get ArgumentOutOfRangeException. Accepted values are Default, SequentialAccess, CloseConnection, and SequentialAccess | CloseConnection.
Suggested fix
- Change the cref on line 382 to
ArgumentOutOfRangeException. - Optional: in
doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml, the public docs listArgumentException("The CommandBehavior value is invalid."). That is accurate because it's the base class, butArgumentOutOfRangeExceptionis more specific. The same file says "Only SequentialAccess and CloseConnection are supported at the batch level" and doesn't mention thatDefaultis also accepted.
The helper name NotSupportedCommandBehavior likely caused the mismatch. Renaming it is out of scope here; it's also used by SqlCommandSet.
Found while documenting SqlBatch behavior in the SqlClient docs on Microsoft Learn.
- Dominant language
- C#
- Stars
- 994
- Forks
- 342
- Avg merge
- 5d 9h
- Merged PRs (30d)
- 56
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/SqlClient
-
Sync ExecuteReader on an STA thread deadlocks against a StateChange handler that marshals to the UI thread (OpenAsyncRetry path)Possibly taken @mdaigle claimed this 23 days ago. OpenExternal :link:
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
dotnet/SqlClient#4534 · 2 comments · 1 assignee ·
Maintainers usually reply within 2 days
-
Area\Tests
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
dotnet/SqlClient#4377 · 2 comments ·
Maintainers usually reply within 2 days
-
InternalsVisibleTo In Nonstandard LocationPossibly taken @priyankatiwari08 claimed this 3 days ago. OpenCode Health :pill: Good First Issue :sparkles:
Difficulty 1/5 Under an hour Newbie friendliness 76/100
dotnet/SqlClient#3029 · 2 comments ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
dotnet/SqlClient#4826 · 2 comments ·
Maintainers usually reply within 2 days
-
Area\AKV Provider
Difficulty 5/5 Over a week Newbie friendliness 35/100
dotnet/SqlClient#4802 · 1 comment ·
Maintainers usually reply within 2 days
All issues in dotnet/SqlClient
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
rjmurillo/moq.analyzers#1468 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
[誤判定] `define` が `デフィね`・`デフィ値` になるPossibly taken A pull request linked to this issue is open or already merged. Open再現済み 要トリアージ 誤判定
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
yksr-melt/Meltype#421 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Facepunch/sbox-public#12063 · 1 comment ·
Maintainers usually reply within 2 days