Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

SqlBatch.ValidateExecuteCommandBehavior XML comment says NotSupportedException but code throws ArgumentOutOfRangeException

Open Beginner friendly
#4,823 1 comment 0 reactions 0 assignees View on GitHub

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

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.

SqlBatch.cs line 382:

/// <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

  1. Change the cref on line 382 to ArgumentOutOfRangeException.
  2. Optional: in doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml, the public docs list ArgumentException ("The CommandBehavior value is invalid."). That is accurate because it's the base class, but ArgumentOutOfRangeException is more specific. The same file says "Only SequentialAccess and CloseConnection are supported at the batch level" and doesn't mention that Default is 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

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/SqlClient

All issues in dotnet/SqlClient

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.