{"record":{"id":"779ed5a3874c9a4a","repo":"DapperLib/Dapper","slug":"type-779ed5","errorCode":null,"errorMessage":"type","messagePattern":"type","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Dapper/SqlMapper.GridReader.Async.cs","lineNumber":54,"sourceCode":"            /// </summary>\r\n            /// <remarks>Note: the row can be accessed via \"dynamic\", or by casting to an IDictionary&lt;string,object&gt;</remarks>\r\n            public Task<dynamic> ReadSingleAsync() => ReadRowAsyncImpl<dynamic>(typeof(DapperRow), Row.Single);\r\n\r\n            /// <summary>\r\n            /// Read an individual row of the next grid of results, returned as a dynamic object\r\n            /// </summary>\r\n            /// <remarks>Note: the row can be accessed via \"dynamic\", or by casting to an IDictionary&lt;string,object&gt;</remarks>\r\n            public Task<dynamic?> ReadSingleOrDefaultAsync() => ReadRowAsyncImpl<dynamic?>(typeof(DapperRow), Row.SingleOrDefault);\r\n\r\n            /// <summary>\r\n            /// Read the next grid of results\r\n            /// </summary>\r\n            /// <param name=\"type\">The type to read.</param>\r\n            /// <param name=\"buffered\">Whether to buffer the results.</param>\r\n            /// <exception cref=\"ArgumentNullException\"><paramref name=\"type\"/> is <c>null</c>.</exception>\r\n            public Task<IEnumerable<object>> ReadAsync(Type type, bool buffered = true)\r\n            {\r\n                if (type is null) throw new ArgumentNullException(nameof(type));\r\n                return ReadAsyncImpl<object>(type, buffered);\r\n            }\r\n\r\n            /// <summary>\r\n            /// Read an individual row of the next grid of results\r\n            /// </summary>\r\n            /// <param name=\"type\">The type to read.</param>\r\n            /// <exception cref=\"ArgumentNullException\"><paramref name=\"type\"/> is <c>null</c>.</exception>\r\n            public Task<object> ReadFirstAsync(Type type)\r\n            {\r\n                if (type is null) throw new ArgumentNullException(nameof(type));\r\n                return ReadRowAsyncImpl<object>(type, Row.First);\r\n            }\r\n\r\n            /// <summary>\r\n            /// Read an individual row of the next grid of results.\r\n            /// </summary>\r\n            /// <param name=\"type\">The type to read.</param>\r","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/DapperLib/Dapper/blob/72a54c475f75e18cb93cba0809d00a5e6e49efd9/Dapper/SqlMapper.GridReader.Async.cs#L36-L72","documentation":"GridReader.ReadAsync(Type type, bool buffered) is the non-generic async overload that materializes the next result grid into instances of a runtime Type. It throws ArgumentNullException(nameof(type)) at SqlMapper.GridReader.Async.cs:54 when type is null. The generic ReadAsync<T> overloads cannot hit this because typeof(T) is always non-null.","triggerScenarios":"Call grid.ReadAsync((Type)null) on a GridReader from QueryMultipleAsync. Typical when the Type comes from a variable, reflection, or a config lookup that resolved to null.","commonSituations":"Mapping result sets by type loaded via Type.GetType(name) where the name was wrong and returned null; deserialization dispatch tables with a missing entry; runtime polymorphic readers.","solutions":["Null-check type before the call: if (type is null) throw ...; or fall back to a default type.","Prefer the generic overload ReadAsync<T>() which makes a null type unrepresentable.","Validate the Type source (Type.GetType / Assembly.GetType) for null immediately after resolution and log the failing type name."],"exampleFix":"// before\nType t = Type.GetType(typeName); // null if not found\nvar rows = await grid.ReadAsync(t);\n\n// after\nType t = Type.GetType(typeName) ?? throw new InvalidOperationException($\"Unknown type: {typeName}\");\nvar rows = await grid.ReadAsync(t);","handlingStrategy":"validation","validationCode":"if (type is null) throw new InvalidOperationException(\"type must be resolved before reading a grid\");\nvar rows = await grid.ReadAsync(type);","typeGuard":"static Type? ResolveType(string name) => Type.GetType(name);\n// before use:\nType t = ResolveType(name) ?? throw new InvalidOperationException($\"Unresolved type {name}\");","tryCatchPattern":null,"preventionTips":["Prefer generic ReadAsync<T>() over the Type-based overload.","Resolve Types once at startup and reject nulls with a named error.","Use Type.GetType with the fully qualified assembly-qualified name."],"tags":["dapper","gridreader","async","argumentnullexception","type-resolution"],"backgroundTag":null,"analyzedSha":"72a54c475f75e18cb93cba0809d00a5e6e49efd9","analyzedAt":"2026-08-13T14:18:18.115Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}