ErrLookup › Background articles › ArgumentException — when a .NET method rejects an argument that breaks its contract

ArgumentException — when a .NET method rejects an argument that breaks its contract

ArgumentException is the .NET exception thrown when a method receives an argument that is the right type but semantically invalid: an unrecognized enum token, a null where a value is required, an index past the valid range, or a name that collides with an existing one. Developers meet it at the call site, before any work begins, with a message that usually names the offending parameter and lists the valid values. Across the 2040 documented records spanning 75 repositories, it is the most common shape of fail-fast guard in the .NET ecosystem.

Distilled from 2,040 documented records across 75 repositories.

Background

System.ArgumentException is the .NET base class for a method argument that is the correct type but violates the method's semantic contract. Unlike NullReferenceException or IndexOutOfRangeException, which signal a bug the caller did not anticipate, ArgumentException is an intentional guard the library author placed at the method boundary. Every one of these 30 records is from a C#/.NET library, and in each case the throw happens on the first line of validation — before any structural change, before any side effect. HyperlinkUriValidator.RequireSafeScheme checks the URL scheme before writing the hyperlink (record 0); AudioFileWriter.Write checks the running byte count against the RIFF ceiling before each buffer flush (record 1); Job.Validate checks the type-method relationship before a job is enqueued (record 16).

The family exists as a fail-fast replacement for silent corruption. Multiple records state that the exception was introduced to kill a prior silent-accept behavior that produced broken output: the WAV writer guards against overflowing the unsigned 32-bit data-size field, which would produce an unreadable file; OfficeCLI's legend-position parser used to silently coerce unknown tokens to 'bottom', leaving the file contradictory with its success message (record 4); the defined-name collision check prevents Excel's 'found a problem' repair dialog (record 5); the boolean retype guard (record 24) prevents a stamping of t="b" onto text content that Excel rejects with error 0x800A03EC. The throw is a design decision: the author chose a clean, early exception over a late, confusing failure or a corrupt artifact.

From the caller's side the exception is deterministic and self-documenting. It fires on the specific call whose argument violates the contract — the Nth write that pushes the cumulative total past 4 GiB, the Set call whose narrowed source range leaves a pivot field index pointing past the new column count (record 2). The constructor takes both a message and a paramName, so the exception identifies which argument is at fault, and the message frequently enumerates the valid set verbatim: "Valid: top, bottom, left, right, topRight" (record 4); "Valid: sum, average, count, countNums, max, min, stdDev, var, none, custom" (record 9); "only http, https, mailto, ftp, ftps, sftp, news, tel, sms, file, about, and ppaction" (record 0). This makes ArgumentException one of the most actionable exception classes in .NET: the fix is usually stated in the message itself.

The family clusters into several distinct shapes across libraries. Allowlist guards reject tokens outside a known enumerated set — URI schemes, registry hive aliases, chart legend and label positions, totals-row functions, wallpaper styles. Capacity guards reject values that exceed a physical or format limit — the WAV 4 GiB ceiling, the Excel 1,048,576-row ceiling, array dimensions of zero or less. Consistency guards reject duplicates and type mismatches — defined-name collisions at the same scope, toolbar button ID conflicts, a Job whose declaring type does not match the method. Lookup guards reject references to unregistered targets — YARP policy names not in the DI dictionary (records 19, 25), workflow node IDs not in the steps map (record 14). Format guards reject content that does not match its declared form — image magic bytes disagreeing with the file extension (record 17), a ChannelId key not parseable as a Guid in N format (record 11). One record (29, Maui's BindableProperty) is an internal-consistency case where the coercion and validation callbacks disagree after a value is clamped. The behavior on edge cases is library-specific: some validators trim and case-normalize before matching (record 4's SchemaKeyNormalizer), others are case-sensitive and do not trim (record 3's registry hive parser, record 27's Enum.TryParse).

Common causes

What usually fixes it

Documented occurrences

…and 2,020 more across the corpus — use search.

Honest provenance: generated on 2026-08-13 from AI-assisted analysis of the linked records. See how records are made.