DapperLib/Dapper · error · ArgumentNullException
type
Error message
type
What it means
GridReader.Read(Type type, bool buffered) is the synchronous non-generic overload that reads the next grid into instances of a runtime Type, throwing ArgumentNullException(nameof(type)) at SqlMapper.GridReader.cs:130 when type is null. The generic Read<T> overload cannot hit this.
Source
Thrown at Dapper/SqlMapper.GridReader.cs:130
/// </summary>
/// <typeparam name="T">The type to read.</typeparam>
public T ReadSingle<T>() => ReadRow<T>(typeof(T), Row.Single);
/// <summary>
/// Read an individual row of the next grid of results.
/// </summary>
/// <typeparam name="T">The type to read.</typeparam>
public T? ReadSingleOrDefault<T>() => ReadRow<T>(typeof(T), Row.SingleOrDefault);
/// <summary>
/// Read the next grid of results.
/// </summary>
/// <param name="type">The type to read.</param>
/// <param name="buffered">Whether to buffer the results.</param>
/// <exception cref="ArgumentNullException"><paramref name="type"/> is <c>null</c>.</exception>
public IEnumerable<object> Read(Type type, bool buffered = true)
{
if (type is null) throw new ArgumentNullException(nameof(type));
return ReadImpl<object>(type, buffered);
}
/// <summary>
/// Read an individual row of the next grid of results.
/// </summary>
/// <param name="type">The type to read.</param>
/// <exception cref="ArgumentNullException"><paramref name="type"/> is <c>null</c>.</exception>
public object ReadFirst(Type type)
{
if (type is null) throw new ArgumentNullException(nameof(type));
return ReadRow<object>(type, Row.First);
}
/// <summary>
/// Read an individual row of the next grid of results.
/// </summary>
/// <param name="type">The type to read.</param>
View on GitHub (pinned to 72a54c475f)
Solutions
- Null-check the Type before calling and surface the unresolved name.
- Use the generic Read<T>() overload to make the error a compile-time one.
- Centralize Type resolution in a helper that throws on null.
Example fix
// before
Type t = Type.GetType(name); // null if unresolved
var rows = grid.Read(t);
// after
Type t = Type.GetType(name) ?? throw new InvalidOperationException($"Unresolved type {name}");
var rows = grid.Read(t); Defensive patterns
Strategy: validation
Validate before calling
if (type is null) throw new InvalidOperationException("type must be resolved before reading a grid");
var rows = grid.Read(type); Type guard
Type t = Type.GetType(name) ?? throw new InvalidOperationException($"Unresolved type {name}"); Prevention
- Prefer generic Read<T>().
- Resolve Types at startup and reject nulls with a named error.
- Use assembly-qualified names with Type.GetType.
When it happens
Trigger: Call grid.Read((Type)null) — usually a Type variable from reflection or a lookup that returned null.
Common situations: Type.GetType returning null for an unresolvable assembly-qualified name; dispatch tables with a missing mapping; conditional Type selection without an else.
Related errors
- type
- This operation requires an identity or a connected command
- The reader has been disposed; this can happen after all data
- An item with the same key has already been added
- The member {name} of type {type.FullName} cannot be used as
AI-assisted analysis of DapperLib/Dapper@72a54c475f (2026-08-13).
Data as JSON: /api/errors/94e107aebe433909.
Report an issue: GitHub.