Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

SqlBatch.ValidateExecuteCommandBehavior XML comment says NotSupportedException but code throws ArgumentOutOfRangeException

Chiusa Adatta ai principianti
#4,823 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@apoorvdeshmukh ci sta già lavorando.

Dal 13/10/2026.

  • #4878 di @mdaigle — integrata

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
90/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp

Direzione di ricerca

Inizia dal commento /// su ValidateExecuteCommandBehavior in src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBatch.cs (intorno alla riga 382) e controlla l'helper NotSupportedCommandBehavior in AdapterUtil.cs, che restituisce ArgumentOutOfRangeException. Esegui SqlBatchTest.cs in tests/UnitTests (righe 22 e 32) per confermare il tipo atteso. È fatto quando il cref indica ArgumentOutOfRangeException e i test unitari continuano a passare; la formulazione in doc/snippets SqlBatch.xml è facoltativa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C#
Stelle
996
Fork
351
Merge medio
4g 20h
PR unite (30g)
67

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dotnet/SqlClient

Tutte le issue di dotnet/SqlClient

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.