ErrLookup › Background articles › ArgumentNullException ("Value cannot be null"): when a .NET method rejects a null argument

ArgumentNullException ("Value cannot be null"): when a .NET method rejects a null argument

ArgumentNullException with the message "Value cannot be null" is thrown when .NET code passes a null reference for an argument a method requires to be non-null. It is raised by explicit fail-fast guards in libraries such as Newtonsoft.Json, Hangfire, Orleans, MAUI, LiteDB, Unity, and Polly, and its ParamName names the offending argument. This page covers the mechanism behind the whole family, how the message varies across libraries, and the causes and fixes that hold no matter which library threw it.

Distilled from 701 documented records across 41 repositories.

Background

ArgumentNullException is the canonical .NET exception for a method that received a null reference for an argument it requires to be non-null. Libraries raise it from an explicit guard clause near the top of a method, either `throw new ArgumentNullException(nameof(param))` or the newer `ArgumentNullException.ThrowIfNull(param)`, and the thrown instance carries a `ParamName` property identifying the offending argument. The base-class message format is "Value cannot be null. (Parameter 'X')".

The reason the family exists is fail-fast diagnosis. Without the guard, the same null would dereference several frames later as a NullReferenceException giving no clue which argument caused it. The records describe this repeatedly: Newtonsoft.Json funnels dozens of public entry points through a single `ValidationUtils.ArgumentNotNull` guard; LiteDB "fails fast on the public API surface so the caller sees the real cause"; dotnet/maui's RendererPool rejects a null `oldElement` at construction rather than letting it surface deep inside the swap logic. The guard converts a confusing downstream NRE into a precise, local signal.

From the caller's side the experience is uniform, but the message text varies by library and constructor overload. Several entries surface only the bare parameter name, because those guards used the paramName-only constructor: Newtonsoft's message "is literally the parameter name", CefSharp's is "browser", Hangfire's is "client" or "storage". Others show the full "Value cannot be null. (Parameter 'key')" form (BenchmarkDotNet). A few embed a descriptive sentence (Unity: "Cannot add custom dependency on an empty custom dependency."; ABP: "concerns should be provided!"). One group is actively misleading: dotnet/orleans throws ArgumentNullException for a non-positive TimeSpan timeout, so the message reads "Value cannot be null" for a value that is not null at all, and the records advise reading it as "invalid timeout value".

The family also varies in what counts as null and where the guard lives. LiteDB's Query.EQ treats empty and whitespace strings as null via IsNullOrWhiteSpace, and Unity's DependsOnCustomDependency rejects empty strings too. Some guards live in property setters (Hangfire's SqlServerStorageOptions.SqlClientFactory), some fire at object construction (RelayCommand, EnvironmentVariable, AssetIdentifier), and some are extension-method null-this checks (CefSharp, Hangfire's client.Schedule, Polly's timeoutProvider). What unifies them is the contract: a reference the method cannot operate on was supplied, and the library refuses to proceed.

Common causes

What usually fixes it

Go deeper

Documented occurrences

…and 681 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.